In my httpd.ini I redirect all traffic from "example.co.uk" to "www.example.co.uk", the below works fine for this:

RewriteCond %HTTPS off 
RewriteCond Host: (?!^www.example.co.uk)(.+) 
RewriteRule /(.*) http\://www.example.co.uk/$2 [I,RP]

I have a bunch of microsites which also use this website, say "www.foobar.co.uk", set in the Host Headers of IIS 6. With the above rules, "www.foobar.co.uk" ends up at "www.example.co.uk"!

Is there a RewriteCond I can do against the request to make sure that the request is for "example.co.uk" to not capture the microsites and rewrite those? Or even better, a way I can take any request, be it "example.co.uk" or "foobar.co.uk" and just wack a www in front of it?

Thanks for your help.


I made this work with multiple URLs (and Andrews help), with the below.

RewriteCond %HTTPS off 
RewriteCond Host: (?!^www.+)(.+) 
RewriteRule /(.*) http\://www.$1/$2 [I,RP]

Try using the following:

RewriteCond %HTTPS off 
RewriteCond Host: !^www\..+ 
RewriteCond Host: ^(example|foobar)\.co\.uk
RewriteRule /(.*) http\://www.$1.co.uk/$2 [I,RP]
  • Unfortunately, this doesn't work "example.co.uk" and "foobar.co.uk" stay as such, no www. on the front. It no longer breaks www.foobar.co.uk anymore though, but then it doesn't do anything else either :(. – MagicalArmchair Jun 14 '12 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.