Isapi 重写 301 重定向解析为 404 - 循环引用?

发布于 2024-07-26 07:59:16 字数 963 浏览 10 评论 0原文

我正在尝试使用 IIS Isapi Rewrite 执行以下操作...

我需要将 seo 友好的 URL(默默地)转换回应用程序友好的 URL,如下所示:

RewriteRule ^/seo-friendly-url/ /test/index.cfm [I,L]

足够简单。

但我还需要已经在搜索引擎中编入索引的 URL(例如)301 重定向到 seo 友好的版本。 就像这样:

RewriteRule ^/test/index.cfm    /seo-friendly-url/ [I,R=301]

这些中的每一个都可以单独工作。 但是,当我的 .ini 文件中都包含这两个文件时,我最终会在浏览器地址栏中显示 /seo-Friendly-url/ ,但我收到的是 404 错误。(是的,/test/index.cfm 确实存在!

)我知道它看起来像循环引用,但第一条规则仅重写 IIS 和应用程序之间的 URL - 没有重定向,因此我不会再次点击 Isapi Rewrite。 还是我错了?

我已启用 Isapi Rewrite 日志记录,并且看到以下内容:

HttpFilterProc SF_NOTIFY_PREPROC_HEADERS
DoRewrites
New Url: '/seo-friendly-url/'
ApplyRules (depth=0)
Rule 1 : 1
Result (length 15): /test/index.cfm
ApplyRules (depth=1)
Rule 1 : -1
Rule 2 : 1
Result (length 18): /seo-friendly-url/
ApplyRules: returning 301
ApplyRules: returning 1
Rewrite Url to: '/seo-friendly-url/'

有人有任何想法吗?

I'm trying to use IIS Isapi Rewrite to do the following...

I need seo-friendly URLs to be (silently) converted back to application friendly URLs like so:

RewriteRule ^/seo-friendly-url/ /test/index.cfm [I,L]

Simple enough.

But I also need URLs already indexed in search engines (for example) to be 301 redirected to the seo-friendly version. Like so:

RewriteRule ^/test/index.cfm    /seo-friendly-url/ [I,R=301]

Each of these works fine in isolation. But when I have both in my .ini file I end up with /seo-friendly-url/ showing in my browser address bar but I'm being served a 404. (Yes, /test/index.cfm definitely exists!)

I know it looks like a circular reference, but the first rule only rewrites the URL between IIS and the application - there's no redirect, so I'm not hitting Isapi Rewrite a second time. Or am I wrong about that?

I've enabled logging on Isapi Rewrite and I'm seeing the following:

HttpFilterProc SF_NOTIFY_PREPROC_HEADERS
DoRewrites
New Url: '/seo-friendly-url/'
ApplyRules (depth=0)
Rule 1 : 1
Result (length 15): /test/index.cfm
ApplyRules (depth=1)
Rule 1 : -1
Rule 2 : 1
Result (length 18): /seo-friendly-url/
ApplyRules: returning 301
ApplyRules: returning 1
Rewrite Url to: '/seo-friendly-url/'

Anyone got any ideas?

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

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

发布评论

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

评论(2

灯角 2024-08-02 07:59:16

这里有两个不同的重写,如果做得正确,它应该可以工作

  1. 客户端用户代理永远不会看到第一个重写。 它请求 /seo-Friendly,您可以在内部重写它并响应

  2. 第二个并不是真正的重写,而是重定向。 你将其发送回客户端,它会重新请求 /seo 友好 - 我认为你需要使用 [R=301,L] 来表示这是行尾 - 只需返回它(L 确实)那)

You have two different rewrites here and it should work if you do it right

  1. The first one is never seen by the client user-agent. It requests /seo-friendly and you rewrite it internally and respond

  2. The second one is not really a rewrite, but a redirect. You send that back to the client and it re-requests the /seo-friendly -- I think you need to use [R=301,L] to say that this is the end of the line -- just return it (L does that)

指尖凝香 2024-08-02 07:59:16

通过一些尝试和错误,我想出了一个解决方案。

使用 $ 符号指定重定向匹配位于字符串的末尾:

RewriteRule ^/test/index.cfm$    /seo-friendly-url/ [I,R=301]

使重写的 URL 与重定向匹配字符串略有不同 - 在本例中添加不必要的“?”:

RewriteRule ^/seo-friendly-url/ /test/index.cfm? [I,L]

Through some trial and error I've come up with a solution for this.

Specify that the redirect match is at the end of the string using the $ symbol:

RewriteRule ^/test/index.cfm$    /seo-friendly-url/ [I,R=301]

Make the rewritten URL trivially different from the redirect match string - in this case adding an unnecessary "?":

RewriteRule ^/seo-friendly-url/ /test/index.cfm? [I,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文