新梦想网络 > 客服中心 > 独立服务器 > 正文缩放字号: [收藏本问题]

win2008服务器设置301跳转的方法

时间:2014-08-05来源:新梦想网络 作者:新梦想网络 点击:
 win2008服务器使用的是iis7,实现301跳转可以通过web.config操作。
 301跳转代码:


 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="301Redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^ceshi\.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.ceshi.com/{R:0}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

 
 这串代码实现的功能是ceshi.com跳转到www.ceshi.com,将第9行和第11行的ceshi.com改成自己的域名即可。然后把这串代码加到网站根目录下的web.config里面相应的位置即可。
 下面举例说明一下应该加到哪个位置

 原web.config代码如下:
 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
                <add value="index.asp" />
                <add value="index.php" />
                <add value="default.aspx" />
                <add value="default.asp" />
                <add value="index.htm" />
                <add value="index.aspx" />
                <add value="default.php" />
                <add value="default.html" />
            </files>
        </defaultDocument>
        <httpRedirect enabled="false" destination="" exactDestination="false" httpResponseStatus="Found" />
    </system.webServer>
</configuration>

  添加301后的代码如下:
  
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
                <add value="index.asp" />
                <add value="index.php" />
                <add value="default.aspx" />
                <add value="default.asp" />
                <add value="index.htm" />
                <add value="index.aspx" />
                <add value="default.php" />
                <add value="default.html" />
            </files>
        </defaultDocument>
        <httpRedirect enabled="false" destination="" exactDestination="false" httpResponseStatus="Found" />
 
<rewrite>
<rules>
<rule name="301Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^ceshi\.com$" />
</conditions>
<action type="Redirect" url="http://www.ceshi.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
 
    </system.webServer>
</configuration>
 
  因为原web.config已经有了</configuration>则只需要把蓝色的那一部分加进去即可,如果没有web.config,则新建一个txt然后重命名为web.config即可。

  win2003服务器设置301的方法:http://www.xmxwl.net/help/member/20140313/13256.html
 

    TAG:

    下载此文章 (欢迎转载,请注明出处:http://www.xmxwl.net/help/member/20140805/13360.html)