1

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

kost
  • 325
  • 1
  • 9
  • 29
  • Does it need to support an array of words to convert from singular to plural (e.g. *category* to *categories*) or just that one instance? – Sᴀᴍ Onᴇᴌᴀ Jan 01 '17 at 02:11
  • Βy an array of words you mean multiple pages ? If yes Sam do you have an web.config example of how can I achieve it ? – kost Jan 01 '17 at 10:11

1 Answers1

1

In IIS, I created a new rule:

enter image description here

Then in the next dialog, I added a Pattern categories_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 here enter image description here

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

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

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.

Community
  • 1
  • 1
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
  • Many many thanks for your detailed answer Sam. One last question...Is that possible is a shared hosting environment ? I cannot create an inbound rule in IIS 8.5 because I don't have the rights to access IIS administration. Does the web.config can work without the creating the inbound rule ? – kost Jan 01 '17 at 22:08
  • I actually haven't tried it in a shared hosting environment, so I am not sure. I know the UI dialog listed _inbound rule_ but the xml in the *web.config* file doesn't contain that keyword so I think it should be okay... ¯\\_(ツ)_/¯ – Sᴀᴍ Onᴇᴌᴀ Jan 02 '17 at 17:52