【问题标题】:IIS Rewriting with Query String and Question Mark IIS 7使用查询字符串和问号 IIS 7 重写 IIS
【发布时间】:2011-09-02 11:30:36
【问题描述】:

我已经阅读了主题,但我仍然无法解决,我知道我的问题,但想知道是否可以为我指明正确的方向。

我已经设置了一个规则:

www.mydomain.com/productlist.asp?CategoryID=2

改写成

www.mydomain.com/homeware/cushions

.

            <rule name="cushions">
                <match url="^homeware/cushions" />
                <action type="Rewrite" url="productlist.asp?CategoryID=2" />
            </rule>

好的,现在我的问题是结果的分页,所以当用户进入下一页时的原始域如下所示:

www.mydomain.com/productlist.asp?CategoryID=2&Page=2

这是我遇到问题的地方 - 我希望它变成:

www.mydomain.com/homeware/cushions?page=2

持续多少页 只是无法让它工作 - 我知道我需要使用查询字符串但真的很挣扎。寻求专业知识,感谢您的帮助

【问题讨论】:

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


    【解决方案1】:

    要捕获查询字符串,您需要为此使用条件,因为匹配 URL 不包含它。 所以你可以用这样的规则来做到这一点:

    <rule name="cushions" stopProcessing="true">
    <match url="^homeware/cushions$" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="page=(\d+)" />
    </conditions>
    <action type="Rewrite" url="productlist.asp?CategoryID=2&amp;page={C:1}" appendQueryString="false" /> 
    

    【讨论】:

      【解决方案2】:

      只需在操作中添加 appendQueryString="true" 将自动附加查询字符串。

      <rewrite>
              <rules>
                  <rule name="test">
                      <match url="^homeware/cushions" />
                      <action type="Rewrite" url="/test/test.cfm?category=5" appendQueryString="true" />
                      <conditions>
                      </conditions>
                  </rule>
              </rules>
          </rewrite>
      

      http://localhost:8081/homeware/cushions?page=2 您将在 URL 变量中收到值为 2 的页面。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-22
        • 1970-01-01
        • 1970-01-01
        • 2011-10-29
        • 1970-01-01
        相关资源
        最近更新 更多