How To Rewrite The Url Of A Webpage In IIS UrlRewriteModule With Web.config?

- 1 answer

I search for a rule (or a set of rules) that eliminate the extensions of the html files but at the same time to be able to rewrite the browser url like the example below:

category1_pageid2.html to categories_page (more seo friendly)

I have a shared hosting environment with IIS 8.5 with IIS_UrlRewriteModule 7.1.1952.0

Many thanks for your help



In IIS, I created a new rule:

enter image description here

Then in the next dialog, I added a Patterncategories_page with conditions for {QUERY_STRING} matching pattern c=(\d+)&p=(\d+) (though you may not need a query string - customize per your needs). And for the Action I added a Rewrite URL of category{C:1}_pageid{C:2}.html. If you don't need the query string, then you can un-check that checkbox for append query string.

enter image description hereenter image description here

Looking at the web.config file for the site, I see the XML below:

<?xml version="1.0" encoding="UTF-8"?>
                <rule name="category-page">
                    <match url="categories_page" />
                    <action type="Rewrite" url="category{C:1}_pageid{C:2}.html" />
                        <add input="{QUERY_STRING}" pattern="c=(\d+)&amp;p=(\d+)" />

When trying this in my browser, I see the category1_pageid2.html page when I naveigate to localhost/categories_page?c=1&p=2:

enter image description here

Other options include a rewrite map - see this answer for a short explanation.