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代码如下:
下面举例说明一下应该加到哪个位置
原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后的代码如下:
因为原web.config已经有了</configuration>则只需要把蓝色的那一部分加进去即可,如果没有web.config,则新建一个txt然后重命名为web.config即可。添加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>
发表评论