代码之家  ›  专栏  ›  技术社区  ›  pedrofernandes

url rewriter.net和多个查询字符串

  •  2
  • pedrofernandes  · 技术社区  · 15 年前

    我在强调为我的网站创建一个url rewriter.net规则。

    我有一个链接

     http://localhost/Pages/CategoryList.aspx?ID=2&Page=1
    

    我想换成这个

     http://localhost/Category/2.aspx?Page=1
    

    我尝试了以下方法:

    <rewrite url="~/Category/(.+).aspx?Page=(.+)" to="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" /> 
    

    但它不起作用。

    有人能帮我吗?

    5 回复  |  直到 15 年前
        1
  •  0
  •   Pavlo Neiman    15 年前

    这会起作用

    <rewrite url="~/Category/(.+).aspx(\?(.*))?" to="~/Pages/CategoryList.aspx?ID=$1&amp;$3" />
    
        2
  •  2
  •   Stefan    15 年前

    试试这个:

    <rewrite url="~/Category/([0-9]+)\.aspx\?Page=([0-9]+)" to="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />
    

    或更好(更短):

    <rewrite url="~/Category/(d+)\.aspx\?Page=(d+)" to="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />
    

    我想你用的“.”太贪婪了,匹配太多了。

        3
  •  0
  •   John Rasch    15 年前

    你是否添加了:

    <httpModules>
          <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
    </httpModules>
    

    对你 web.config 文件?

        4
  •  0
  •   Kamarey    15 年前

    你忘了转义一些特殊符号(“‘和’?’)不确定“~”:

    <rewrite url=".*/Category/(.+)\.aspx\?Page=(.+)" to="/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />
    
        5
  •  0
  •   Rubens Farias    15 年前

    试试这个:

    <rewrite url="~/Category/(.+)\.aspx\?Page=(.+)" 
             to ="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />