帮助中心

如果没有找到你需要的问题,随时联系我们

帮助中心

利用URL Rewrite的web.config 和 httpd.ini实现301域名重定向2023/5/12 0:49:46
 

从优化搜索引擎角度出发,301重定向是网址重定向比较可行的一种办法。当网站的当前域名不可用或者发生变更后,搜索引擎只对新网址进行索引,同时又会把旧地址下原有的外部链接如数转移到新地址下,从而不会让网站的排名因为网址变更而收到丝毫影响。


同样,在使用301永久性重定向命令让多个域名指向网站主域时,也不会对网站的排名产生任何负面影响。


301重定向有助于增加网站的权重,如将所有站点权重都集中于 一个域名


注意:要做重定向的域名一定都要绑定并解析在该主机上才能生效

一.下面简单阐述一下对Windows虚拟主机用户的实现301重定向的方法:

例如:将ranthost.com 定向到www.ranthost.com 这个域名上。


Windows server 2003 IIS6.0虚拟主机下301重定向代码


httpd.ini文件 配置的代码如下:


[php]

[ISAPI_Rewrite]


CacheClockRate 3600


RepeatLimit 32


RewriteCond Host: ^ranthost\.com$


RewriteRule (.*) http\://www\.ranthost\.com$1 [I,R]


[/php]

下载地址:httpd.ini


复制以上代码,写入httpd.ini文件然后上传到网站根目录即可。记住把其中的ranthost.com域名换成你的域名。


Windows server 2008 IIS7.5虚拟主机下的urlrewrtie规则


web.config文件代码如下:


[php]

<?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="^ranthost.com$" />

</conditions>

<action type="Redirect" url="http://www.ranthost.com/{R:0}" redirectType="Permanent" />

</rule>

</rules>

</rewrite>

</system.webServer>

</configuration>

[/php]

下载地址:web.config


复制以上代码,,写入web.config文件然后上传到网站根目录即可。记住把其中的ranthost.com域名换成你的域名。


二.多个域名重定向怎么处理?

当然,被重定向的域名可以有多个,该怎么处理。往下看。


1.httpd.ini 配置文件中需要另写一行重定向代码。


[php]

[ISAPI_Rewrite]


CacheClockRate 3600


RepeatLimit 32


RewriteCond Host: ^ranthost\.com$


RewriteRule (.*) http\://www\.ranthost\.com$1 [I,R]


RewriteCond Host: ^idc.ranthost\.com$


RewriteRule (.*) http\://www\.ranthost\.com$1 [I,R]

[/php]

2. web.config配置文件中只需在被重定向的域名后面加一个竖线"|"跟上需要被重定向的增加域名即可。


像这样:


[php]

<?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="^ranthost.com|idc.ranthost.com$" />

</conditions>

<action type="Redirect" url="http://www.ranthost.com/{R:0}" redirectType="Permanent" />

</rule>

</rules>

</rewrite>

</system.webServer>

</configuration>

[/php]




 
             

联系方式

全国热线:

13373902052

客服QQ: