我正在努力(并且史诗般地失败)找出实现以下永久301重定向的必要规则:
www.mysite.com > mysite.com
mysite.com/oldfolder > mysite.com
www.mysite.com/oldfolder > mysite.com
mysite.com/oldfolder/old-file > mysite.com/old-file
www.mysite.com/oldfolder/old-file > mysite.com/old-file
如果有任何了解IIS7重写模块的人可以提供帮助,我将非常感激!
答案 0 :(得分:0)
您只需要添加如下规则:
请求的网址: 匹配模式
使用:正则表达式
图案: oldfolder
忽略大小写:true
动作类型:重定向
重定向网址:htt://www.mysite.com
追加查询字符串:false 重定向类型301
答案 1 :(得分:0)
为了将来的参考,对于其他任何做类似事情的人来说,这是我们最终使用的总规则:
<rewrite>
<rules>
<!--To always remove trailing slash from the URL-->
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
<!-- redirects blog/2012/10/post to /post. -->
<rule name="Redirect blog with dates to root" stopProcessing="true">
<match url="^blog/([0-9]+)/([_0-9]+)/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?mydomain.com$" />
</conditions>
<action type="Redirect" url="http://{C:0}/{R:3}" redirectType="Permanent" />
</rule>
<!-- redirects blog/post to /post. -->
<rule name="Redirect blog to root" stopProcessing="true">
<match url="^blog/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?mydomain.com$" />
</conditions>
<action type="Redirect" url="http://{C:0}/{R:1}" redirectType="Permanent" />
</rule>
<!-- redirects case-studies/case-study to /case-study. -->
<rule name="Case studies redirect." stopProcessing="true">
<match url="^case-studies/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?mydomain.com$" />
</conditions>
<action type="Redirect" url="http://{C:0}/{R:1}" redirectType="Permanent" />
</rule>
<!-- for SEO the www is stripped from the URL. -->
<rule name="Canonical host name.">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^mydomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://mydomain.com/{R:1}" />
</rule>
<!-- removes index.php from the URL. -->
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>