【发布时间】:2015-11-02 15:32:28
【问题描述】:
如果阅读一些帖子并编写此代码...但它不起作用。我在同一个主机帐户中有 2 个域。我喜欢根据访问者使用的域将访问者重定向到 Flash 或 WordPress 站点。 这是我的代码:
<?php
$host = $_SERVER['SERVER_NAME'];
if($host == 'elfarosociedades.com.ar' or $host == 'http://www.elfarosociedades.com.ar/' or $host == 'http://elfarosociedades.com.ar/' or $host == 'www.elfarosociedades.com.ar') {
header('Location: http://www.elfarosociedades.com.ar/index.php');
else
header('Location: http://villarincondelsol.com.ar/home.html');
}
?>
【问题讨论】:
-
打印出
$_SERVER['SERVER_NAME']的值并确保它是您所期望的。你可能想要$_SERVER['HTTP_HOST']。 -
谢谢我也试过了,还有 SELF,但什么也没发生,我的还好吗?或者应该有“??
-
当前也无法正常工作:
<?php $host = $_SERVER['SERVER_HOST']; if($host == 'elfarosociedades.com.ar' or $host == 'http://www.elfarosociedades.com.ar/' or $host == 'http://elfarosociedades.com.ar/' or $host == 'www.elfarosociedades.com.ar') { header('Location: http://www.elfarosociedades.com.ar/arg/index.php'); else header('Location: http://villarincondelsol.com.ar/home.html'); } ?> -
再次打印出
$host,看看它的值是多少。很有可能这不是你所期望的。在header调用之后,您可能还需要exit。别再胡乱编造像SERVER_HOST这样不存在的东西了。 -
最好
stripos()而不是定义url的所有可能条件。