我正在使用IIS7的URL重写模块来完成几件事:
- 301从非www到www 的重定向规则
- 301重定向规则.info到.com(移至我域的.com版本)
- 301从旧页面重定向规则,例如/page-name.asp to Just/page-name
我已经能够将前两个结合到一个规则中,第三项是它自己的规则。问题是在要求URL的情况下生成了两个301重定向:
site.info/page-name.asp/
首先完成了301
www.site.com/page-name.asp(例如,添加了www,.info转到.com)
然后,从中完成了第二个301
www.site.com/page-name
我的问题是:如何组合这些,以便仅发生一个301重定向而不是两个?这是他们当前位于我的web.config中的两个规则:
<rule name="SEO - 301 Redirect - .info to .com AND force WWW" stopProcessing="false">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^site.info$" />
</conditions>
<action type="Redirect" url="{ToLower:http://www.site.com/{R:1}}" redirectType="Permanent" />
</rule>
<rule name=".aspVersion-to-friendlyvia301" stopProcessing="false">
<match url="(.*).asp" />
<action type="Redirect" url="{R:1}" />
</rule>
我似乎已经找到了自己问题的答案。它有点黑客,但是完成了所有必需的URL转换(例如,拖延斜线删除,非www到www,tolowercase,删除目录的默认文档以及任何其他必要的重定向,例如页名称更改)。
我所谈论的问题实际上称为" 301个重定向的链接",在这里,解决方案的提出相当优雅:
:http://www.seomoz.org/blog/what-every-seo-seo-should-know-about-iis-iis#chaning
此解决方案来自上一个注释:
1)而不是 redirect 应用重写带有附加符号_
2)添加将赶上URL的新规则始于_并应用重定向
<rule name="LowerCaseRule1" stopProcessing="false">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{R:1}" pattern="[A-Z]" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="_{ToLower:{R:1}}" />
</rule>
<rule name="RemoveTrailingSlashRule1" stopProcessing="false">
<match url="(.*)/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="_{R:1}" />
</rule>
<rule name="Final redirect" stopProcessing="true">
<match url="^(_+)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Redirect" url="{R:2}" />
</rule>