Using mod rewrite to redirect non-www URL to www URL on IIS

How we used Helicon ISAPI Rewrite 3 to redirect URLS without www to the correct www URL on IIS 7.5

Without some form of mod rewrite installed you need to create an additional site in IIS and redirect using an ASP or HTML file in the folder that the site points to, which results in twice as many sites to maintain in IIS Manager.

We have used Helicon Rewrite 3 for some time to provide friendly URLs in our SSIDM content managements system, and also use it for solving the non-www URL problem, using the script below:-

# Helicon ISAPI_Rewrite configuration file
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*)\.(com|org|net)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=permanent,L]
RewriteCond %{HTTP_HOST} ^([^.]*)\.(co\.uk)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=permanent,L]
RewriteCond %{HTTP_HOST} ^([^.]*)\.(org\.uk)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=permanent,L]
RewriteCond %{HTTP_HOST} ^([^.]*)\.(ltd\.uk)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=permanent,L]

 


Website design by ReZolve. An SSIDM website - v2.6.005 [2]. Loaded in 0.0537 seconds.