【问题标题】:ASP.Net Url Rewrite Url Having too many redirectsASP.Net Url Rewrite Url 重定向过多
【发布时间】:2021-03-03 22:23:43
【问题描述】:

我有一个网站,其中包含位于文件夹中的 .aspx 文件,并且该页面的当前路径类似于 /giveaway/giveaway.aspx。我添加了一个 url 重写规则,以在用户输入 somedomain.com/giveaway 时自动将用户定向到所述页面,但是我收到错误

 `This page isn’t working 
 `somedomain.com redirected you too many times.`

谁能告诉我我在这里做错了什么?以下是我的规则

<rewrite>
  <rules>
    <rule name="Redirect to HTTPS">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
    <rule name="Giveaway" stopProcessing="true">  
        <match url="^giveaway*" />  
        <action type="Rewrite" url="/giveaway" appendQueryString="false" />  
      </rule>  
     <rule name="GiveawayRedirect" stopProcessing="true"> 
       <match url="^giveaway*" /> 
       <action type="Redirect" url="/Giveaway/giveaway.aspx" appendQueryString="false" redirectType="Permanent" /> 
     </rule> 
  </rules>
  <outboundRules>
    <rule name="Add SameSite" preCondition="No SameSite">
      <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
      <action type="Rewrite" value="{R:0}; SameSite=strict" />
      <conditions>
      </conditions>
    </rule>
    <preConditions>
      <preCondition name="No SameSite">
        <add input="{RESPONSE_Set_Cookie}" pattern="." />
        <add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=strict" negate="true" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

【问题讨论】:

  • 这个^giveaway 基本上意味着/giveaway。因此,您将循环发送重定向,因为您将其发送到url="/giveaway"
  • 而且规则GiveawayRedirect永远不会到达,因为规则和上面的一样。
  • 所以我只需要顶级规则?
  • 不,顶级规则是在循环中发送它的规则。您可能只需要底部的那个。 (正如你所发现的)

标签: asp.net url redirect url-rewriting


【解决方案1】:

因为我的路径是 /giveaway/giveaway,它一直在循环,因为它曾经多次找到关键字。我将路径更改为 /contest/giveaway,现在当用户键入“/giveaway”时,它会重定向到 /contest/giveaway 并正常工作。

这是我的规则

<rule name="GiveawayRedirect" stopProcessing="true">
           <match url="^giveaway*" />
           <action type="Redirect" url="/contest/giveaway" appendQueryString="false" redirectType="Permanent" />
         </rule>

【讨论】:

    猜你喜欢
    • 2015-10-02
    • 1970-01-01
    • 2010-12-24
    • 2022-01-16
    • 1970-01-01
    • 2018-07-25
    • 2013-07-18
    • 2016-12-03
    • 1970-01-01
    相关资源
    最近更新 更多