asp.net - ASP.NET Web.config URL 重写正则表达式
问题描述
我正在尝试清理一些返回 404 而不是 200 的请求。
例如有人有这样的链接到我的网站:
http://example.com/?publisher=123456
我正在尝试添加一个重写规则来处理这种情况,如下所示:
<rule name="Redirect publisher" stopProcessing="true">
<match url="(.*)\/\?publisher=(.*)$" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false"></conditions>
<action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="The requested URL was not found." />
</rule>
但是,我遵循了Microsoft 的说明,即使我的测试表明上述正则表达式应该可以工作,但什么也没有发生。我尝试做一个更常见的重定向,如下所示:
<action type="Redirect" url="https://{HTTP_HOST}" redirectType="Permanent" />
然而,又没有任何反应。好像我的正则表达式不好还是什么?
解决方案
我终于弄明白了:
<rule name="Redirect publisher" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="publisher" negate="false" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="The requested URL was not found." />
</rule>
推荐阅读
- angular - Ionic 3:离子选择中的异步管道在选择之前返回 null
- java - 使用 Java 锁时出现竞争条件的可能性
- c# - 关于问号和冒号的 C# 语法问题
- ios - 如何在 iOS 13 的 UISegmentedControl 中更改段的颜色?
- r - 除了 geom_histogram 中的 binning,我还学习了另一种方法,您可以在 x 轴上对连续变量进行分类,但在网上找不到
- rest - 在 Delphi 中使用 Indy 的 GitHub API
- php - 一组 Excises 数组、向量和更多数组 Pt 1
- java - 在 Spring MVC 上实现 HTTP PATCH 的正确方法是什么?
- javascript - 如何在fabricjs 2.x版中保持SVG图像比例/视口放大?
- python - 如何让子弹跟随鼠标