16
votes

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>
2

2 Answers

34
votes

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" />
0
votes

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" />