Iis 7 IIS 7.5 URL重写-从URL重写文件夹

Iis 7 IIS 7.5 URL重写-从URL重写文件夹,iis-7,url-rewriting,iis-7.5,Iis 7,Url Rewriting,Iis 7.5,我使用IIS 7.5和URL重写 我有一个具有以下文件层次结构的网站: webroot webroot/LegacySite webroot/和legacy/在IIS中都是独立的应用程序文件夹 我需要重写我的URL,以便: 如果请求被删除,URL将被重写为 下面我的Web.Conf(在webroot文件夹中)无法正常工作,您能指出我缺少什么吗 <?xml version="1.0" encoding="UTF-8"?> <configuration>

我使用IIS 7.5和URL重写

我有一个具有以下文件层次结构的网站:

webroot
webroot/LegacySite
webroot/和legacy/在IIS中都是独立的应用程序文件夹


我需要重写我的URL,以便:

  • 如果请求被删除,URL将被重写为
下面我的
Web.Conf
(在webroot文件夹中)无法正常工作,您能指出我缺少什么吗

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="MyRole" stopProcessing="true">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^mysite.com" />
                            <add input="{PATH_INFO}" pattern="^\LegacySite\" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\LegacySite\{R:0}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

以下各项应起作用:

<rule name="MyRole" stopProcessing="true">
    <match url="LegacySite/(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^mysite.com$" />
    </conditions>
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>

您可能希望删除用于检查主机名的条件。这真的很重要吗?您是否有任何其他域名绑定到该网站,而您不希望发生重定向?这似乎没有必要。您可能只需要:

<rule name="MyRole" stopProcessing="true">
    <match url="LegacySite/(.*)" />
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>

我添加了
appendQueryString=“true”
以将任何(可选)查询字符串参数传递给重写的URL