【问题标题】:IIS URL redirect directoryIIS URL 重定向目录
【发布时间】:2017-01-30 22:42:12
【问题描述】:

我在使用 IIS URl 重定向模块时遇到问题。 尝试从 www.site.com/directory1/default.aspx 重定向 到 www.site.com/directory2/default.aspx

所以对目录 1 的任何请求都需要转到目录 2。我将禁用目录 1 中的应用程序 有任何想法吗? 目前我有以下,但不工作。

<rewrite>
            <rules>
                <remove name="Portal Test Redirect" />
                <rule name="Portal Test Redirect" patternSyntax="Wildcard">
                    <match url="*directory1/*" ignoreCase="false" />
                    <conditions />
                    <serverVariables />
                    <action type="Rewrite" url="{R:1}/directory2/{R:2}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>        

【问题讨论】:

    标签: asp.net iis url-routing http-redirect


    【解决方案1】:

    你需要改变你的规则如下

    <rewrite>
        <rules>            
            <rule name="Portal Test Redirect">
                <match url="(.*)(directory1)(.*)" patternSyntax="ECMAScript"/>
                <action type="Rewrite" url="{R:1}directory2{R:3}" />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

    • 这也可以处理查询字符串参数吗?我只需要更改目录
    • 是的,应该是,但我还没有测试过。
    • 您还在遇到问题吗?
    • 在应用程序级别之外使用注册为allowDefinition='MachineToApplication'的部分是错误的。此错误可能是由于虚拟目录未在 IIS 中配置为应用程序所致。
    • 这与 URL Rewrite 规则无关。看起来您在子 web.config 中添加了一个不允许的部分。您能否确认您在哪里添加规则以及您在哪个部分收到此错误?
    【解决方案2】:

    1.打开旧页面所在目录下的web.config 2.然后为旧位置路径和新目的地添加代码如下:

    <configuration>
      <location path="services.htm">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://domain.com/services" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
      <location path="products.htm">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    </configuration>

    试试上面的。引用自Setting up redirect in web.config file

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-11
      • 2015-01-14
      • 2011-06-24
      相关资源
      最近更新 更多