开发者

Redirecting from www.host.com to host.com in .htaccess

Can someone please provide me with the proper dire开发者_StackOverflow中文版ctives in .htaccess file to have www.host.com requests to be redirected to host.com and vice versa?


This will redirect from http://www.yoursite.com to http://yoursite.com:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^yoursite\.com
RewriteRule (.*) http://yoursite.com/$1 [R=301, L]

And this is the reverse:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]

The above is what I use on my server, and it works perfectly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜