用.htaccess文件做301重定向(加上或去掉WWW)

用.htaccess文件做301重定向(加上或去掉WWW)

去掉网址的www
#规范域名
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.toyu.org$
RewriteRule ^(.*)$ http://toyu.org/$1 [R=301,L]
把toyu.org换成你的域名就行了,下面修改方法相同。

让网址全部加上www
#规范域名
RewriteEngine on
RewriteCond %{HTTP_HOST} ^toyu.org$
RewriteRule ^(.*)$ http://www.toyu.org/$1 [R=301,L]

把其他网址重定向到新域名
#规范域名
RewriteEngine on
RewriteCond %{HTTP_HOST} ^其他域名.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.其他域名.com$
RewriteRule ^(.*)$ http://www.toyu.org/$1 [R=301,L]

把网址首页也规范一下
把index.html、index.php等重定向到index.php
#规范域名
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ http://www.toyu.org/ [R=301,L]

检查一下是否成功
可以用这个免费工具检查一下转向的效果:
http://www.internetofficer.com/seo-tool/redirect-check/

Add Comment

Required fields are marked *. Your email address will not be published.