Friday 13 June 2008

URL rewriting with multiple websites

Less exciting than my previous posts I'm afraid (safely back in the UK now).

I recently consolidated a number of websites onto a single Windows 2003 server. One such site (dokuwiki) used url-rewriting via ISAPI Rewrite to present user-friendly URLs. Unfortunately our original rewriting configuration broke the other websites as it tried to re-write their url's also!

Although I'm happy to pay the $99 for the full version of ISAPI Rewrite, I was pleased that we could solve the problem with the Lite one by using the RewriteCond directive, e.g.:

RewriteCond %{HTTP:Host} =ourWikiHostName
RewriteRule ^/_media/(.*)\?(.*)$ /lib/exe/fetch.php?media=$1&$2 [L]
RewriteCond %{HTTP:Host} =ourWikiHostName
RewriteRule ^/_detail/(.*)\?(.*)$ /lib/exe/detail.php?media=$1&$2 [L]

The same technique will also prove useful in hosting multiple .Net 3.5 web services on the same server, e.g.:
RewriteCond %{HTTP:Host} =webServiceHostName RewriteRule RewriteRule ^/(.*)$ /service.svc/$1 [L]