Using ISAPI_Rewrite to fine tune URL re-writing

Jack Simpson

Head of Marketing and Communications

Lorem ipsum et cetera

I finally feel like I can go to bed with the website ready to face the world.  The last big hurdle is the multiple hostnames we own that we would like associating with the main website www.webapplicationsuk.com.  Most notably, www.webappuk.com and www.webapplicationsuk.co.uk, both of which we own currently.  Although I could just add them as portal aliases they would then be indexed separately by search engines (e.g. Google), to the detriment of the site ranking.  Instead it’s necessary to issue a 301 redirect (permanent redirect) when  navigating to a page on a ‘holding URL’.

This is especially important as our hostname has always historically been www.webappuk.com.  Last year I made the decision to use the longer, but more ‘guessable’ www.webapplicationsuk.com, which we’ve since marketed heavily.  Unfortunately, all our rankings are based on the old URL, 301 redirects can sort that out.

A second issue I had was with our heavily publicised http://www.webapplicationsuk.com/rss.xml RSS Feed.  Obviously, it would be a disaster to lose this feed, however, to use URL Master et al then XML would have to be registered on the ASP handlers to allow the .NET Framework to process all incoming .xml requests, something of an overkill when we only want this one instance handling.

This is where ISAPI_Rewrite comes into play.

It’s a very complex, but powerful tool.  Unfortunately, the lack of documentation didn’t make it easier, however, the following configuration file achieved everything I wanted:

   1: [ISAPI_Rewrite]

   2:  

   3: RewriteEngine on

   4:  

   5: RewriteCond Host: ^www.webappuk.co(.+)

   6: RewriteRule /(.*) http://www.webapplicationsuk.com/$2 [I,RP]

   7:  

   8: RewriteCond Host: ^www2.webappuk.co(.+)

   9: RewriteRule /(.*) http://www2.webapplicationsuk.com/$2 [I,RP]

  10:  

  11: RewriteCond Host: ^www.webapplicationsuk.co.(.+)

  12: RewriteRule /(.*) http://www.webapplicationsuk.com/$2 [I,RP]

  13:  

  14: RewriteCond Host: ^www2.webapplicationsuk.co.(.+)

  15: RewriteRule /(.*) http://www2.webapplicationsuk.com/$2 [I,RP]

  16:  

  17: # Defend your computer from some worm attacks

  18: RewriteRule .*(?:global.asa|default.ida|root.exe|..).* . [F,I,O]

  19: RewriteRule ^/rss.xml /CustomRss.aspx [L,I]

Lines 5-15 are the key host-rewriters, mapping  our various hosted domains to www(2).webapplicationsuk.com, ensuring that we only have one location for each piece of information (a key requirement for good SEO).  I used www2 for ‘offline’ pre-release testing of the site.

Line 19 quickly allows rss.xml to be mapped to our custom rss feeder that aggregates news and blogs.