In the IIS7 URL Rewrite module, can I specify in a redirect rule to not apply to http-post requests?

心不动则不痛 提交于 2019-11-30 01:49:05

问题


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>

回答1:


You have access to that in the {REQUEST_METHOD} variable under the conditions.

<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />



回答2:


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.

<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="GET" ignoreCase="true" />


来源:https://stackoverflow.com/questions/5994261/in-the-iis7-url-rewrite-module-can-i-specify-in-a-redirect-rule-to-not-apply-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!