【问题标题】:IIS rewrite URL in asp.net goes to into infinity loopasp.net 中的 IIS 重写 URL 进入无限循环
【发布时间】:2020-11-05 02:42:43
【问题描述】:

我只需要在我的 web 配置文件中创建一个规则来将所有 URL 重写到规则中

例如: url/services/presentations-evenementielles 到 url/Services/Presentations-Evenementielles

这一切都是为了 SEO 目的,以避免重复。

<rule name="ProductionRule2" stopProcessing="true" patternSyntax="ExactMatch" >
                <match url="^/productions/xyz" ignoreCase="true" />
                <action type="Redirect" url="Productions/XYZ" redirectType="Permanent"/>
              </rule>

上面的代码给了我无限循环错误。

【问题讨论】:

  • 如果您忽略大小写,那么当然会导致无限循环,因为如果您唯一要做的就是更改大小写,它将保持与相同的值匹配。
  • @mason,能否提供规则,以便我实施
  • docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/… 了解如何调试。顺便说一句,匹配模式可能是错误的。
  • 目前,如果重定向 URL 不同,则此规则可以正常工作。如果根据给定的 URL 重定向 URL,那么它会进入重定向循环。

标签: asp.net iis url-rewriting web-config webmatrix


【解决方案1】:

你的规则有一些错误

1.您试图在完全匹配规则中使用“^”。请设置为正则表达式

2.您正在尝试在匹配网址中使用“/”。 domain/productions/xyz 的匹配 url 部分是 productions/xyz 而不是 /production/xyz。

3.当您将 URL 重定向到自身时启用忽略大小写。

所以请尝试像这样修改规则

<rule name="ProductionRule2" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="^productions/xyz" ignoreCase="false" />
                <action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
              </rule>

更新:

请像这样修改规则

<rule name="ProductionRule2" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="^Productions/XYZ" ignoreCase="false" negate="true" />
                <action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
                    <conditions>
                        <add input="{ToLower:{URL}}" pattern="/productions/xyz" />
                    </conditions>
              </rule>

这对我有用

请记住在测试规则时清理浏览器缓存。并且 URL 应该是 proODuctions/Xyz 而不是 proODuction/Xyz。

【讨论】:

  • 嗨,它工作正常,但如果在我的 url 中像 proODuction/Xyz 则不工作。
  • @BrijeshPatel。我认为您可以将条件模式更改为“与 Productions/XYZ 不匹配”并启用 ignoreCase。
  • 那么如何添加不匹配的条件呢?并保持 ignoreCase="false"
  • 请尝试
  • 不,因为它不起作用,它再次进入无限循环。
猜你喜欢
  • 2018-06-09
  • 2012-01-01
  • 1970-01-01
  • 2013-01-25
  • 1970-01-01
  • 2015-08-06
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
相关资源
最近更新 更多