【问题标题】:Redirect to a page without Query String using Re-write module in asp.net使用asp.net中的重写模块重定向到没有查询字符串的页面
【发布时间】:2015-08-05 17:12:14
【问题描述】:

我必须创建一个重写规则,它将重定向如下 URL

abc.com/ssss/aaaaa/fff.aspx/?homeredirect=ture

abc.com/ssss/aaaaa/fff.aspx

abc.com/fff.aspx/?homeredirect=ture

abc.com/fff.aspx

我不知道该怎么做。

我试过下面的方法,但它对我不起作用

 <rule name="Mb" enabled="true" stopProcessing="true">
      <match url ="^([_A-Z0-9a-z-]+)/?homeredirect=true" ignoreCase="false"/>
      <conditions logicalGrouping ="MatchAll" trackAllCaptures="false">
        <add input ="{HTTP_HOST}" pattern="^(www.)?abc.com$"/>
        <add input ="{REQUEST_URI}" pattern="ModuleId" negate="true"/>
      </conditions>
      <action type="Rewrite" url="/{R:1}"/>
    </rule>

请帮帮我。

【问题讨论】:

    标签: c# asp.net url-rewriting web-config rewrite


    【解决方案1】:

    从 URL Rewrite 的角度来看,“url”属性中的问号在正则表达式的上下文中表示“零或一”。

    要在重写规则中使用查询字符串,请将其设为条件。这类似于 mod_rewrite 在 Apache 中对查询字符串的处理。

    另外,最好转义任何可能对正则表达式有意义的字符,例如句点。

    对于 IIS URL 重写模块:

    <!-- Remove homeredirect=true from query string for URLs ending in .aspx -->
    <rule name="Mb" enabled="true" stopProcessing="true">
      <!-- Match any URL ending in ".aspx/" -->
      <match url="\.aspx/$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www\.)?abc\.com$" />
    
        <!-- Match if the query string includes "homeredirect=true" -->
        <add input="{QUERY_STRING}" pattern="homeredirect=true" />
      </conditions>
    
      <!-- Redirect to the URL without the query string -->
      <action type="Redirect" url="/{R:0}" />
    </rule>
    

    查看URL Rewrite Module Configuration Reference了解更多详情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 2019-09-24
      • 2015-12-13
      相关资源
      最近更新 更多