网站改版之后,URL地址变更后对SEO影响巨大,需要做301跳转。
网上几乎找不到带参数的301规则方法,于是分享出来。
IIS直接修改web.config文件方法:
<rule name="event" stopProcessing="true">
<match url="^改版前url地址" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="新版url地址" />
</rule>
<rule name="newsshow" stopProcessing="true">
<match url="^news.php$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{QUERY_STRING}" pattern="^id=([0-9]*)$" />
</conditions>
<action type="Redirect" url="news_{c:1}.html" appendQueryString="false" redirectType="Permanent"/>
</rule>
例子改版前url地址为news.php?id=23,改版后地址为news_23.html。
其中?可省略,([0-9]*)为任意数字变量,{c:1}为和变量相同的内容。
www和无www域名做301跳转可提升网站权重,对SEO帮助很大。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="https://www.a.com$S$Q" exactDestination="true" httpResponseStatus="Permanent" />
<rewrite>
<rules>
<rule name="301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^on$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.a.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
静态化网页对SEO有很大帮助,真实静态化最佳,虚拟静态化比较简单方法如下:
修改web.config文件方法
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!--无参数-->
<rule name="Index" stopProcessing="true">
<match url="^index.html" />
<action type="Rewrite" url="index.php" />
</rule>
<!--一个参数-->
<rule name="Rule1" stopProcessing="true">
<match url="^news_([0-9]+).html" />
<action type="Rewrite" url="news.php?nid={R:1}" />
</rule>
<!--多个参数 -->
<rule name="Rule2" stopProcessing="true">
<match url="news_list_([0-9]+)_([0-9]+).html" />
<action type="Rewrite" url="news_list.php?nid={R:1}&page={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
其中{R:1}为参数,多个参数可以写{R:2} {R:3};
([0-9]+)和参数相同的内容,此正则表达式为任意数字;
(.*)为任意字符数字字母等等,name一定不可以重名哦。