我试图在一个地方有两个不同的网站,第一个网站有wordpress,第二个网站没有wordpress。当访问者来自affiliate.webmediamagazine.com要加载wordpress时,直接加载另一个自定义索引时,我使用以下代码:
http://affiliate.webmediamagazine.com/index.php
<form action='http://www.webmediamagazine.com' method='post' name='frm'>
<input type='hidden' name="affiliate" value="yes">
</form>
<script language="JavaScript">
document.frm.submit();
</script>
http://webmediamagazine.com/index.php
<?php
$affiliate = $_POST['affiliate'];
if ($affiliate == yes) {include 'indexwp.php';}
else {include 'indexcustom.php';}
?>
indexwp.php是wordpress默认的index.phpindexcustom.php是一个简单的php脚本。
应该在服务器(Apache?Nginx?…?)配置文件中将其配置为虚拟主机。
Apache 示例
编辑:
例如,在共享主机上,您可以将wordpress文件放在~/www/wordpress/
文件夹中。
然后使子域(affiliate.webmediamagazine.com
)指向该目录。大多数时候,它可以在主机提供的管理面板中完成。
如果你真的是这样的话。。。当访客来自,然后只使用简单的重定向:
<?
switch ( $_SERVER['HTTP_REFERER'] ) {
default:
header( 'Location: /indexcustom.php' ); die;
break;
case 'affiliate.webmediamagazine.com':
header( 'Location: /indexwp.php' ); die;
break;
}
?>
或者使用$_SERVER['HTTP_HOST'],如果您需要知道访问者在哪个domain
中。
但正如其他人已经说过的,在这种情况下,最好在apache
级别配置所有内容,以便使用干净的WordPress安装的不同目录。
编辑
你确定你没有忘记代码中单词yes周围的'
吗?
<?php
$affiliate = $_POST['affiliate'];
if ($affiliate == 'yes') { include 'indexwp.php'; }
else {include 'indexcustom.php';}
?>
我现在做到了,使用phpcookie来存储,但不是从子域,而是从目录。