使用htaccess将所有域别名重定向到一个

时间:2012-09-03 13:25:00

标签: .htaccess redirect

我有一些域别名,而我只想要其中一个实际使用。 目前,我已经安装了两个域,

重定向我想使用htaccess。

我的网域目前的工作原理如下:

www.domain.com/index.html - 主域名的主页

www.secondDomain.com/index.html - 显示与主域完全相同的主页,但我希望它在使用时自动将网址重命名为www.domain.com/index.html。

谢谢!

1 个答案:

答案 0 :(得分:18)

匹配%{HTTP_HOST}不等于www.domain.com并将其重定向到规范域是一件简单的事情。

RewriteEngine On
# If the hostname is NOT www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
# 301 redirect to the same resource on www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
相关问题