I need 301 redirect for all urls like
xyz.com/searchitems?key1=val1&key2=val2 to be like
xyz.com/searchitems
i.e. I want query string to be removed from URL. I have written this so far in my web.config
<rewrite>
<rules>
<rule name="Rewrite to searchitems">
<match url="^searchitems?$" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:0}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
but it is making redirect loop
Edit:
I wat the querystring to be removed just for this url "xyz.com/searchitems" and not for all urls. There can be any number of query string params in urls.
"^(.*searchitems)\?.+$"Regex r = new Regex(@"^(.*searchitems)\?.+$"); var b1 = r.IsMatch("xyz.com/searchitems?qsdfj=qsdkfj%20"); var b2 = r.IsMatch("xyz.com/searchitems?key1=val1&key2=val2"); var b3 = r.IsMatch("xyz.com/searchitems"); var b4 = r.Matches("xyz.com/searchitems?qsdfj=qsdkfj%20");