当你准备好好看这篇文章的时候,你应该已经知道了301重定向的作用与意义了,那么这里就不多加解释了。
那么我唯一想提的就是关于域名带与不带www的区别,并且301重定在其中的意义,详情:域名带与不带www的区别
这里我们以将域名“hl22.com”重定向到“www.hl22.com”为例
Windows虚拟主机用户的实现301重定向的方法:
Windows server 2003 IIS6.0虚拟主机下301重定向代码
httpd.ini文件配置的代码如下,放置位置:网站根目录
[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32
RewriteCond Host: ^hl22\.com$
RewriteRule (.*) http\://www\.hl22\.com$1 [I,R]
复制代码注:记得把其中的域名换成你的域名。如果你的网站根目录中的这个文件已经存在(伪静态),可以将上面的代码直接加到里面
Windows server 2008 IIS7.5虚拟主机下的urlrewrtie规则
web.config文件代码如下,放置位置:网站根目录
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^hl22.com[ DISCUZ_CODE_1 ]quot; />
</conditions>
<action type="Redirect" url="http://e.hl22.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
复制代码记得把其中的域名换成你的域名。
二,多对域名重定向怎么写规则?
1、对于httpd.ini 配置文件中需要另写一行重定向代码。
如下,将域名“hl22.com”、“seo.hl22.com”都重定向到“www.hl22.com”
[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32
RewriteCond Host: ^hl22\.com$
RewriteRule (.*) http\://www\.hl22\.com$1 [I,R]
RewriteCond Host: ^seo.hl22\.com$
RewriteRule (.*) http\://www\.hl22\.com$1 [I,R]
复制代码2. web.config配置文件中只需在被重定向的域名后面加一个竖线”|”跟上需要被重定向的增加域名即可。
如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^hl22.com|seo.hl22.com[ DISCUZ_CODE_3 ]quot; />
</conditions>
<action type="Redirect" url="http://e.hl22.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
复制代码注:因为即使是做了301跳转之后,搜索引擎对你另外一个带www的域名还是会有一个考察期的,这个考察与新站稍有不同。权重一般不会丢失。所以做过301跳转后会有一个作用期,不会马上生效!
发表评论