开发者

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

开发者 https://www.devze.com 2023-03-03 01:17 出处:网络
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 h

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

精彩评论

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