虚拟 url 中的 urlrewritING.net 查询字符导致重定向循环

发布于 2024-08-17 07:10:52 字数 920 浏览 10 评论 0原文

我有一个项目,我们正在为客户重新构建一个网站,新网站在 .net 平台上使用 umbraco。旧站点是冷聚变。

Umbraco 利用 urlrewriting.net 库,因此我为旧的冷聚变 url 创建了所有 301 个重复规则,但这一个导致了无限循环。

    <add name="r66" virtualUrl="^~/thing_info/index.cfm.D413249D-BCD8-304B-02CD-561DAC70641E$"
                destinationUrl="~/about-us/award-winning-product" redirect="Application" redirectMode="Permanent" ignoreCase="true" />

我知道 ”。”有特殊含义,但效果很好,我也用过“。”匹配包括“?”在内的任何字符查询字符串的开头字符。 如果我访问尝试不带查询字符串的网址,

http://staging.site/thing_info/index.cfm-D413249D-BCD8-304B-02CD-561DAC70641E

那么我会正确重定向到

http://staging.site/about-us/award-winning-product

但是,如果我尝试该网址(问号是唯一的区别),

http://staging.site/thing_info/index.cfm?D413249D-BCD8-304B-02CD-561DAC70641E

那么我最终会陷入到自身的重定向循环中。 (我检查了响应头)

有谁知道我是否做错了什么或者它是否是 urlrewriting.net 库中的错误?或者如何纠正这个问题?

I've got a project where we're re-building a site for a client, the new site is using umbraco on the .net platform. the old site was cold fusion.

Umbraco utilises the urlrewriting.net library so I created all the 301 recirect rules for the old cold fusions urls but this one is causing an infinite loop.

    <add name="r66" virtualUrl="^~/thing_info/index.cfm.D413249D-BCD8-304B-02CD-561DAC70641E$"
                destinationUrl="~/about-us/award-winning-product" redirect="Application" redirectMode="Permanent" ignoreCase="true" />

I know "." has a special meaning but it works well enough, also I've used "." to match any character including the "?" character beginning the query string.
if I visit try the url without a querystring like so

http://staging.site/thing_info/index.cfm-D413249D-BCD8-304B-02CD-561DAC70641E

then I get redirected correctly to

http://staging.site/about-us/award-winning-product

However if I try the url (question mark is the only difference)

http://staging.site/thing_info/index.cfm?D413249D-BCD8-304B-02CD-561DAC70641E

Then I end up in a redirect loop to itself. (I checked the response header)

Does anyone have any idea if I've done something wrong or if it's a bug in the urlrewriting.net library? or how to correct the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

树深时见影 2024-08-24 07:10:52

默认情况下,UrlRewritingNet 不会在模式匹配中包含查询字符串。要启用此功能,您需要添加以下属性rewriteUrlParameter="IncludeQueryStringForRewrite"

<add name="r66" virtualUrl="^~/thing_info/index.cfm.D413249D-BCD8-304B-02CD-561DAC70641E$"
     destinationUrl="~/about-us/award-winning-product" redirect="Application" redirectMode="Permanent" 
     ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite" />

尝试一下,让我知道它是否有效。

乔纳森

By default UrlRewritingNet will not include the querystring in the pattern match. to enable this you need to add the following attribute rewriteUrlParameter="IncludeQueryStringForRewrite"

<add name="r66" virtualUrl="^~/thing_info/index.cfm.D413249D-BCD8-304B-02CD-561DAC70641E$"
     destinationUrl="~/about-us/award-winning-product" redirect="Application" redirectMode="Permanent" 
     ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite" />

Give this a try and let me know if it works.

Jonathan

客…行舟 2024-08-24 07:10:52

它是一个正则表达式,因此 .表示任何字符。您可以尝试使用 转义点。或者带有 \? 的问题?专门匹配该字符。

Its a regular expression so the . means any character. You could try escaping the dot with . or the question with \? to match that character specifically.

时光倒影 2024-08-24 07:10:52

当我尝试使用 umbraco 和 UrlRewritingNet 进行永久 301 重定向时,我遇到了同样的问题。

读完这篇文章和一些头发拉扯后,我得到了它与 umbraco/config/urlrewriting.config 中的以下条目一起工作

<add name="Rule1885"
      virtualUrl="^~/whats-on/event\.aspx\?id=1885"
      destinationUrl="~/whats-on/event.aspx?id=1822"
      rewriteUrlParameter="IncludeQueryStringForRewrite"
      redirectMode="Permanent"
      redirect="Application"   
      ignoreCase="true" />

这是乔纳森的答案的组合,添加 rewriteUrlParameter="IncludeQueryStringForRewrite" ,并转义 virtualUrl参数正确,解决了这个问题。

I had the same problem when trying to do a permanent 301 redirect using umbraco and UrlRewritingNet.

After reading this and some hair pulling I got it working with the following entry in umbraco/config/urlrewriting.config

<add name="Rule1885"
      virtualUrl="^~/whats-on/event\.aspx\?id=1885"
      destinationUrl="~/whats-on/event.aspx?id=1822"
      rewriteUrlParameter="IncludeQueryStringForRewrite"
      redirectMode="Permanent"
      redirect="Application"   
      ignoreCase="true" />

It was the combination of Jonathan's answer, to add rewriteUrlParameter="IncludeQueryStringForRewrite", and escaping the virtualUrl parameter correctly that sorted it out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文