Iis 7 IIS7 URL 301重定向文件夹和域

Iis 7 IIS7 URL 301重定向文件夹和域,iis-7,url-rewriting,Iis 7,Url Rewriting,我正在尝试(但最终失败)找出必要的规则,以实现以下永久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.my

我正在尝试(但最终失败)找出必要的规则,以实现以下永久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重写模块的人都能帮忙,我将非常感激

您只需添加如下规则:

请求的URL: 符合模式

使用:正则表达式

模式: 旧文件夹

忽略大小写:true

操作类型:重定向

重定向URL:htt://www.mysite.com

追加查询字符串:false
重定向类型301

,以备将来参考,也可供其他做类似事情的人参考。以下是我们最终使用的全部规则:

<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>

对于上下文,我们正在从子目录中的wordpress博客转移到根目录中,但也希望从规范子域重定向到根目录中