两个域名指向一个主机

时间:2014-02-06 08:29:53

标签: php redirect dns hosting host

我有两个域名,只有一个主机。事实是我的主机不接受多个域名。我问主人的支持我该怎么做,他们给了我一部分代码。我的问题是这段代码对我不起作用。有人能帮帮我吗?

<?php

$host = getenv('HTTP_HOST');

if($host == "www.domain1.ch"){
    header("Location: http://www.domain1.ch/index1.htm");
}

else if($host == "www.domain2.ch"){
    header("Location: http://www.domain2.ch/subfolder2/index.htm");
}
?>

在我的主机管理员面板上,我定义了第二个域名的重定向 一个包含此代码的php页面。

提前谢谢你,

尼古拉斯

1 个答案:

答案 0 :(得分:1)

试试这个

<?php

$host = $_SERVER['SERVER_NAME'];

if($host == "www.domain1.ch"){
    header("Location: http://www.domain1.ch/index1.htm");
}

else if($host == "www.domain2.ch"){
    header("Location: http://www.domain2.ch/subfolder2/index.htm");
}
?>
相关问题