【问题标题】:IIS 7.5 URL Rewrite - Rewrite a Folder from an URLIIS 7.5 URL 重写 - 从 URL 重写文件夹
【发布时间】:2012-05-23 20:10:25
【问题描述】:

我使用 IIS 7.5 和 URL 重写。

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

webroot
webroot/LegacySite

webroot/ 和 legacy/ 在 IIS 中都是独立的 App-Folders。


我需要重写我的网址:

在我的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>

【问题讨论】:

    标签: iis-7 url-rewriting iis-7.5


    【解决方案1】:

    以下应该有效:

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

    【讨论】:

      猜你喜欢
      • 2013-01-06
      • 2015-05-11
      • 1970-01-01
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 2012-10-13
      • 2011-10-21
      相关资源
      最近更新 更多