0

我正在尝试(并且非常失败)找出必要的规则来实现以下永久 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 重写模块的人可以提供帮助,我将不胜感激!

4

2 回答 2

0

您应该只需要添加如下规则:

请求的 URL:匹配模式

使用:正则表达式

模式:旧文件夹

忽略大小写:真

动作类型:重定向

重定向网址:htt://www.mysite.com

附加查询字符串:错误重定向类型 301

于 2012-11-07T16:56:25.237 回答
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>
于 2013-02-19T10:58:23.947 回答