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.
精彩评论