iis重写url并在url末尾添加点

发布于 2024-12-11 05:47:42 字数 214 浏览 0 评论 0原文

我的网站有一些外部链接,这些链接错误地在其末尾添加了句点。 (所以,我无法修复它们)。由于入站链接总是好的,我想将这些链接重定向到合法页面。我已经在 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 技术交流群。

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

发布评论

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

评论(4

木槿暧夏七纪年 2024-12-18 05:47:42

这是一个相当老的问题,但由于我最近面临类似的问题,我决定发布我的发现...

我假设在 url 重写模块之前运行的模块之一终止,但有一个例外,阻止请求继续url-rewrite(我怀疑有一些安全检查)。因此,无法通过 url-rewrite 解决您的问题。

一种可能的解决方法是重定向以点“.”结尾的请求。在 Global.asax 的早期阶段,如下所示:

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    if (Context.Request.RawUrl.EndsWith(".aspx."))
    {
        //permanent redirect and end current request...
        Context.Response.RedirectPermanent(Context.Request.RawUrl.TrimEnd('.'), true);
    }
}

这可能远非最佳答案,但至少它完成了工作;)

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:

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    if (Context.Request.RawUrl.EndsWith(".aspx."))
    {
        //permanent redirect and end current request...
        Context.Response.RedirectPermanent(Context.Request.RawUrl.TrimEnd('.'), true);
    }
}

That might be far from optimal answer but at least it gets job done ;)

热情消退 2024-12-18 05:47:42

我使用了一个在 web.config 级别删除所有尾随点的解决方案:

<rule name="RemoveTrailingDots" stopProcessing="false">
    <match url="^(.*[^.])\.+$" />
    <action type="Rewrite" url="{R:1}" />
</rule>

此规则只是在重写规则开始时在内部重写请求 url,允许请求通过正常规则进行处理,而不是被上游捕获

。没有更多规则要应用,并且只想重定向末尾带有点的任何内容,只需将操作类型更改为 Redirect (区分大小写)

I used a solution that removes all trailing dots at the web.config level:

<rule name="RemoveTrailingDots" stopProcessing="false">
    <match url="^(.*[^.])\.+$" />
    <action type="Rewrite" url="{R:1}" />
</rule>

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)

往日情怀 2024-12-18 05:47:42

如果您有一组固定的不正确的入站链接,您可以集中精力重定向 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.

暗藏城府 2024-12-18 05:47:42

在 IIS 8.5 上,我实现了与 GWR 提议的基本相似的东西,但有一个细微的变化。我需要重写操作标记上的属性appendQueryString =“true”。 (也许这是 2016 年的默认设置,但现在需要指定。)

以下是对我有用的方法:

  <system.webServer>
    <modules>
    ...
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <rewrite>
        <rules>
            <rule name="RemoveTrailingDots">
                <match url="^(.*[^.])\.+$" />
                <action type="Rewrite" url="{R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
  </system.webServer>

我必须从此处安装 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:

  <system.webServer>
    <modules>
    ...
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <rewrite>
        <rules>
            <rule name="RemoveTrailingDots">
                <match url="^(.*[^.])\.+
quot; />
                <action type="Rewrite" url="{R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
  </system.webServer>

I had to install the URL Rewrite feature from here: https://www.iis.net/downloads/microsoft/url-rewrite

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