php重定向如果域名
如果你读了一些文章并写下这段代码。。。但它不起作用。我有两个域名在同一个托管帐户。我喜欢根据访问者使用的域名将他们重定向到flash或WordPress站点。 这是我的代码:php重定向如果域名,php,redirect,dns,Php,Redirect,Dns,如果你读了一些文章并写下这段代码。。。但它不起作用。我有两个域名在同一个托管帐户。我喜欢根据访问者使用的域名将他们重定向到flash或WordPress站点。 这是我的代码: <?php $host = $_SERVER['SERVER_NAME']; if($host == 'elfarosociedades.com.ar' or $host == 'http://www.elfarosociedades.com.ar/' or $host == 'http://elfarosoci
<?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');
}
?>
试试这个
<?php
$host = $_SERVER['HTTP_HOST'];
$hosts=array(
'elfarosociedades.com.ar' ,
'http://www.elfarosociedades.com.ar/' ,
'http://elfarosociedades.com.ar/' ,
'www.elfarosociedades.com.ar'
);
if(in_array($host, $hosts)) {
header('Location: http://www.elfarosociedades.com.ar/index.php');
}else {
header('Location: http://villarincondelsol.com.ar/home.html');
}
?>
打印出$\u SERVER['SERVER\u NAME']
的值,并确保它是您期望的值。你可能想要$\u SERVER['HTTP\u HOST']
来代替。谢谢,我也试过了,赛尔夫,但什么都没发生,我的“ok”还是应该有“??当前也不起作用:
再次打印出$host
,看看它的值是什么。很可能它不是您所期望的。您可能需要在头调用后退出。停止随意编造不存在的东西,如服务器主机
。最好是stripos()
而不是定义url的所有可能条件。