【问题标题】:URL Rewriting with Query Strings using IIS URL Rewrite Module使用 IIS URL 重写模块使用查询字符串重写 URL
【发布时间】:2014-03-31 09:07:24
【问题描述】:

我正在尝试重写一个网址,例如:

new_membership?R=1&I=2

到:

agent_new_membership.aspx?R=1&I=2

但我收到一条错误消息:“HTTP Error 404.0 - Not Found”

这是我正在使用的 web.config 代码:

    <rewrite>
  <rewriteMaps>
    <rewriteMap name="Redirects">
      <add key="/administration" value="/administration_main.aspx" />
      <add key="/change_admin_password" value="/admin_change_password.aspx" />
    </rewriteMap>
  </rewriteMaps>

  <rules>
    <rule name="New Membership" stopProcessing="true">
      <match url="^new_membership?R=(\d+)&amp;I=(\d+)$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="agent_new_membership.aspx?R={R:1}&amp;I={R:2}" />
    </rule>

    <rule name="Redirect rule1 for Redirects">
      <match url=".*" />
      <conditions>
        <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Rewrite" url="{C:1}" appendQueryString="false" />
    </rule>        
  </rules>

</rewrite>

我做错了什么?

提前致谢。

【问题讨论】:

    标签: iis-7 url-rewriting query-string


    【解决方案1】:

    这应该适合你:

        <rule name="TestRule" stopProcessing="true">
          <match url="^new_membership\?R=(\d+)&amp;I=(\d+)$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="agent_new_membership.aspx?R={R:1}&amp;I={R:2}" />
        </rule>
    

    【讨论】:

    • 仍然出现同样的错误。我已经根据您的建议更新了原始帖子以包含完整的重写代码,以防它与其他内容发生冲突。
    • 更新了模式,但仍然没有运气:(
    猜你喜欢
    • 2011-04-22
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 2011-10-29
    • 1970-01-01
    相关资源
    最近更新 更多