Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php重定向如果域名_Php_Redirect_Dns - Fatal编程技术网

php重定向如果域名

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

如果你读了一些文章并写下这段代码。。。但它不起作用。我有两个域名在同一个托管帐户。我喜欢根据访问者使用的域名将他们重定向到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'); 
}
?>

试试这个

<?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的所有可能条件。