将域重定向到WWW

时间:2015-04-03 14:44:43

标签: .htaccess redirect

我希望每当客户使用example.com访问我的网站wwww.example.com时,我都会更改网址。我已经使用.htaccess但这样做不正确。

因为现在a-z0-9.example.com也会重定向到www.example.com,我希望这只适用于example.com,而不是重定向到www.example.com

的.htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.eample.com/$1 [L,R=301,NC]

1 个答案:

答案 0 :(得分:0)

使用以下代码为a-z0-9.example.com创建另一个.htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} a-z0-9.example.com [NC]
RewriteRule ^(.*)$ http://www.a-z0-9.example.com/$1 [L,R=301,NC]

我认为这会奏效。

祝你好运!

相关问题