【问题标题】:php redirect if domain namephp重定向如果域名
【发布时间】: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,但什么也没发生,我的还好吗?或者应该有“??
  • 当前也无法正常工作:&lt;?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'); } ?&gt;
  • 再次打印出$host,看看它的值是多少。很有可能这不是你所期望的。在header 调用之后,您可能还需要exit。别再胡乱编造像SERVER_HOST这样不存在的东西了。
  • 最好stripos()而不是定义url的所有可能条件。

标签: php redirect dns


【解决方案1】:

试试这个

<?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'); 
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-17
    • 2021-11-23
    • 2011-03-08
    • 1970-01-01
    • 2017-05-05
    • 2011-08-19
    • 2014-07-03
    • 2014-01-13
    相关资源
    最近更新 更多