###apache主机的重定向和多域名绑定
(1)将www.chinahtml.com/bbs 内容301重定向到:http://bbs.chinahtml.com/ (子目录绑定)
<VirtualHost *:80>
ServerName www.chinahtml.com
DocumentRoot “/home/www/”
Redirect permanent /bbs http://bbs.chinahtml.com/
</VirtualHost>
(2)将 www.chinahtml.com 所有请求都重定向到(另外一个域名的目录下):http://www.chinahtml.com/bbs/
<VirtualHost *:80>
ServerName www.chinahtml.com
DocumentRoot “/home/www/”
RedirectMatch 301 ^(.*) http://www.chinahtml.com/bbs/
</VirtualHost>
(3)访问 www.chinahtml.com 定位到: www.chinahtml.com/bbs
<VirtualHost *:80>
ServerName www.chinahtml.com
ServerAlias bbs.chinahtml.com bbs2.chinahtml.com *.chinahtml.com #多个域名绑定支持泛域名绑定(*),域名直接用”空格“分开
RedirectMatch ^/$ http://www.chinahtml.com/bbs
</VirtualHost>
做好我在index.php加如下内容解决:
function getServerName()
{
$ServerName = strtolower($_SERVER['SERVER_NAME']?$_SERVER['SERVER_NAME']:$_SERVER['HTTP_HOST']);
if( strpos($ServerName,'http://') )
{
return str_replace('http://','',$ServerName);
}
return $ServerName;
}
$url = getServerName();
$url2="http://web.test.com/s/s1/index.php";
if($url=="web1.test.com") header("Location: $url2");
本文转自 holy2009 51CTO博客,原文链接:http://blog.51cto.com/holy2010/730912