Apache .htaccess - 删除www,不包括子域和二级域

时间:2014-07-03 02:49:05

标签: apache .htaccess mod-rewrite redirect

我需要以

的形式重定向任何域名
****.**** (e.g. hello.com, hello.org, hello.ca, hello.net)

www.*****.*****

使用.htaccess - 上面很容易。

我还需要排除任何子域名。所以,如果我有

test.hello.com

它应该去

test.hello.com

而不是

www.test.hello.com

我已使用以下.htaccess文件

实现了上述两个条件
# Exclude any subdomain:
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
# redirect to www.:
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

但除此之外,我现在需要将所有二级域名重定向到www。所以,如果你输入

hello.com.au

应该去

www.hello.com.au

但是如果你输入

test.hello.com.au

你应该去

test.hello.com.au

这可以吗?

0 个答案:

没有答案