iis重写url并在url末尾添加点
我的网站有一些外部链接,这些链接错误地在其末尾添加了句点。 (所以,我无法修复它们)。由于入站链接总是好的,我想将这些链接重定向到合法页面。我已经在 iis.5 的 urlrewrite 模块中尝试了许多规则,但似乎没有任何内容可以捕获此 url。
我在这里看到了有关末尾带有句点的 asp.net url 的其他问题,但我试图在 IIS 重写模块级别捕获这个问题。关于使这项工作有效的任何指示吗?
I have some external links coming into my site which mistakenly had a period added to their ends. (so, I can't fix them). Since inbound links are always good, I want to redirect these links to a legit page. I've tried a number of rules in the urlrewrite module for iis.5 and nothing seems to capture this url.
I've seen other questions on here regarding asp.net urls with periods at the end, but I'm trying to capture this one at the IIS rewrite module level. Any pointers on making this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个相当老的问题,但由于我最近面临类似的问题,我决定发布我的发现...
我假设在 url 重写模块之前运行的模块之一终止,但有一个例外,阻止请求继续url-rewrite(我怀疑有一些安全检查)。因此,无法通过 url-rewrite 解决您的问题。
一种可能的解决方法是重定向以点“.”结尾的请求。在 Global.asax 的早期阶段,如下所示:
这可能远非最佳答案,但至少它完成了工作;)
This is quite an old one but as i was facing similar issue recently i've decided to post my findings...
I assume that one of modules that run prior to url-rewrite module terminates, with an exception, preventing request from continuing to url-rewrite (i suspect some security checks). Thus it is not possible to resolve your issue with url-rewrite.
One possible workaround could be to redirect requests ending with dot '.' at the very early stage in Global.asax, like here:
That might be far from optimal answer but at least it gets job done ;)
我使用了一个在 web.config 级别删除所有尾随点的解决方案:
此规则只是在重写规则开始时在内部重写请求 url,允许请求通过正常规则进行处理,而不是被上游捕获
。没有更多规则要应用,并且只想重定向末尾带有点的任何内容,只需将操作类型更改为
Redirect
(区分大小写)I used a solution that removes all trailing dots at the web.config level:
This rule just rewrites the request url internally at the beginning of my rewrite rules, allowing the request to process through the normal rules instead of being caught upstream
If you don't have any more rules to apply, and just want to redirects anything with dots at the end, just change the action type to
Redirect
(case sensitive)如果您有一组固定的不正确的入站链接,您可以集中精力重定向 URL 的主要部分,而不是点。
例如,使用以下 URL:
http://www.example.com/index.html。
让 IIS Rewrite 查找与“^index.html.*”匹配的 URL 并重定向到您需要的页面。这应该捕获带点和不带点的 URL。
If you have a fixed set of inbound links that are incorrect, you can concentrate on redirecting the main part of the URL, rather than the dot.
For example, with this URL:
http://www.example.com/index.html.
Have your IIS Rewrite look for a URL matching "^index.html.*" and redirect to the page you need. That should catch the URL both with and without the dot.
在 IIS 8.5 上,我实现了与 GWR 提议的基本相似的东西,但有一个细微的变化。我需要重写操作标记上的属性appendQueryString =“true”。 (也许这是 2016 年的默认设置,但现在需要指定。)
以下是对我有用的方法:
我必须从此处安装 URL 重写功能:https://www.iis.net/downloads/microsoft/url-rewrite
On IIS 8.5 I implemented something substantially similar to that proposed by GWR but with one subtle change. I needed the attribute appendQueryString="true" on the Rewrite action tag. (Perhaps this was the default back in 2016, but now needs to be specified.)
Here's what worked for me:
I had to install the URL Rewrite feature from here: https://www.iis.net/downloads/microsoft/url-rewrite