Search code examples
asp.neturl-rewritingumbracoiis-8

How to remove querystring when using Umbraco rewrite


I have a rewrite rule as below to my Umbraco/ASP .Net site

<add name="Test" virtualUrl="^~/category/(.*)" destinationUrl="/category?cat=$1" rewriteUrlParameter="ExcludeFromClientQueryString" ignoreCase="true" />

The idea is if a user types

www.example.com/category/electronics
www.example.com/category/devices
www.example.com/category/food
www.example.com/category/beverages

Everything works as i would expect when they reach the page without any rules and plain URLs i.e.

www.example.com/category?cat=electronics

If i have the above rule it enabled it always adds/forwards the querystring parameter i.e cat= when you click a link on any of the pages above.

How could i stop forwarding/adding the parameter?


Solution

  • You could use below URL rewrite rule:

     <rule name="add query string" stopProcessing="true">
                    <match url="^category/([^/]+)/$" />
    
                    <action type="Redirect" url="http://www.sample1.com/category?cat={R:1}" appendQueryString="false" />
                </rule>
    

    if you did not install URL rite module in iis you could install it from the below link:

    https://www.iis.net/downloads/microsoft/url-rewrite