


【301重定向】301重定向规则和实现方式
编辑您网站根目录下面的.htaccess文件,将以下规则添加到文件末尾,如果没有该文件,请创建一个。
(说明:domain.com就是你要做的域名网址,自己替换就行。)
1.重定向domain.com到www.domain.com
这种重定向旨在使域名唯一,是网站SEO必须要做的,后面重定向www.domain.com到domain.com也是出于同样的原因,只是形式不同。
打开.htaccess文件,加入以下规则。(下面的规则是针对主域名的,子域名要修改)
RewriteEngineOn
RewriteCond%{HTTP_HOST}!^www.domain.com$[NC]
RewriteRule^(.*)$http://www.domain.com/$1[L,R=301]
2.重定向www.domain.com到domain.com
RewriteEngineOn
RewriteCond%{HTTP_HOST}!^domain.com$[NC]
RewriteRule^(.*)$http://domain.com/$1[L,R=301]
3.重定向olddomain.com到www.newdomain.com
RewriteEngineOn
RewriteCond%{HTTP_HOST}!olddomain.com$[NC]
RewriteRule^(.*)$http://www.newdomain.com/$1[L,R=301]
4.重定向olddomain.comtonewdomain.com
RewriteEngineOn
RewriteBase/
RewriteCond%{HTTP_HOST}!olddomain.com$[NC]
RewriteRule^(.*)$http://newdomain.com/$1[L,R=301]
5.重定向domain.com/file/file.php到otherdomain.com/otherfile/other.php
RewriteCond%{HTTP_HOST}^www.domain.com$
RewriteRule^file/file.php$http://www.otherdomain.com/otherfile/other.php[R=301,L]
第二种方式
使用第三方的DNS域名解析服务
www.dnspod.cn
域名显性URL转发实现301。
第三种方式
购买URL转发服务,自己去淘宝看下。



文章评论 本文章有个评论