【问题标题】:Simple IIS URL Redirect using Rewrite rule not working使用重写规则的简单 IIS URL 重定向不起作用
【发布时间】:2016-02-25 19:40:59
【问题描述】:

我正在尝试将任何传入请求重定向到 /redir/ad.asp?id= 到外部域,并保留参数 id

我的正则表达式在这里工作正常:Regex test

以下是web.config 中的规则,使用 Google 作为测试重定向 URL。但是,当我在浏览器中输入 http://localhost:2121/redir/ad.asp?id=750 时,这不起作用。我收到的只是404 - Not Found

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <!-- REWRITE -->
    <rewrite>
      <rules>
        <rule name="RedirectClassicASP" stopProcessing="true">
          <match url="redir\/ad\.asp\?id=(\d+)" />
          <action type="Redirect" url="http://www.google.com" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

有什么想法吗?

【问题讨论】:

    标签: iis url-rewriting iis-7 rewrite url-redirection


    【解决方案1】:

    发现match url 没有考虑查询字符串,这意味着它没有将正则表达式应用于ad.asp 之后的任何内容。

    我必须做的是添加一个输入条件,该条件将查询字符串与一个单独的模式匹配。

    <rewrite>
      <rules>
        <rule name="RedirectOldASPRedirToMailManager" stopProcessing="true">
          <match url="(redir/ad\.asp)" />
          <conditions trackAllCaptures="true">
            <add input="{QUERY_STRING}" pattern="&amp;?(id=[^&amp;]+)&amp;?" />
          </conditions>
          <action type="Redirect" url="http://localhost/MailManager/redirect/{C:1}" appendQueryString="false" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
    

    更多详情请看这里:IIS.net - URL Rewrite

    【讨论】:

      猜你喜欢
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2017-01-13
      相关资源
      最近更新 更多