Reputation: 612
I need to write a redirect to strip off parameters when a certain one exists, but I would like the redirect to be the same as the incoming url, just without the parameters. This is what I had and it doesn't work. I thought if I put the request URI in there without appending the querystring, then it would work but it results in a loop. Has anyone done this before?
<rule name="Remove parameters" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="page=([0-9]+)" />
</conditions>
<action type="Redirect" url="{REQUEST_URI}" appendQueryString="false" />
Upvotes: 3
Views: 9392
Reputation: 10110
The problem with jallen's answer is that the whole query string will be removed, which may not be ideal if you want to maintain certain parts of it. An alternative would be as follows:
<rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(.*)(page=.+)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}{C:3}" appendQueryString="false" />
</rule>
page
parameter page
parameterHence, we use the redirect {C:1}{C:3}
to exclude only the page query string.
Upvotes: 9
Reputation: 612
Got it with the following:
<rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="page=([0-9]+)" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="false" />
Upvotes: 4