在 IIS7 URL 重写模块中,我可以在重定向规则中指定不应用于 http-post 请求吗?
在 IIS7 URL 重写模块中,我可以在重定向规则中指定不应用于 http-post 请求吗?我正在使用 Microsoft 提供的模板来小写所有 url 并附加尾部斜杠。然而,我有一个不符合此规范的 AJAX post 请求,但它们打破了我们的要求,它们被重写为 301。我不担心 SEO 的 POST 请求,所以我更愿意在规则中指定忽略它。以下是我的规则:
<rule name="AddTrailingSlashRule" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
In IIS7 URL Rewrite module, can I specify in a redirect rule to not apply to http-post requests? I am using the templates provided by Microsoft to lowercase all urls and to append a trailing slash. However I have a AJAX post requests that don't meet this specification but they break we they are rewritten as 301s. I am not worried about POST requests for SEO so I would prefer if I could just specify in the rule to ignore it. Below are my rules:
<rule name="AddTrailingSlashRule" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以根据条件访问
{REQUEST_METHOD}
变量中的内容。You have access to that in the
{REQUEST_METHOD}
variable under the conditions.不久前我们遇到了与 OP 相同的问题,然后应用了 patridge 的解决方案,该解决方案工作得很好,直到我们注意到一些 REST DELETE 调用会失败。结果是尾部斜杠重定向使 DELETE 请求中的 GET 得到。
因此我修改了解决方案,使重定向规则仅适用于 GET 请求。
We've had the same problem as the OP a while back, and then applied patridge's solution, which worked fine until we noticed some REST DELETE calls would fail. Turned out to be the trailing slash redirect making GETs out of the DELETE requests.
So I modified the solution to make the redirect rule to apply only to GET requests.