Non www to www but with some exceptions

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 2
Joined: 25 Jul 2012, 04:42

Non www to www but with some exceptions

25 Jul 2012, 04:52

Hi there

I have a bit of a problem and hoping that an ISAPI guru might be able to help. We have been using the "non www to www" rule to good affect but recently we have seen a bit or a problem during out development process. Let me clarify how our development works (In real world examples, "yourcompany" would just be an acronym for the client we are developing for):

1. We develop on a site with yourcompany.iddev.co.uk
2. We then QA it on a site with yourcompany.idqa.co.uk
3 It then goes live on yourcompany.idlive.co.uk but with additional bindings of the real domain attached e.g. yoursite.co.uk and www.yoursite.co.uk.

This is the same process for every client we have.

Now when the site is live, the rule we use works perfectly for the yoursite.co.uk to be redirected to the www. version. However, when we try and access it on the iddev, idqa or idlive domains its redirecting through to:

http://www.yourcompany.iddev.co.uk/

Which is obviously incorrect. What I need is to be able to do is if, within the domain we find iddev, idqa or idlive, exclude it from the redirect. Is this possible? and if so, how would I got about it?

The rule we are using is the standard:

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]

Thank you so much for any help on the above and if it doesn't make sense, hopefully I can try and explain it a little better.

Tom Jenkins

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Non www to www but with some exceptions

25 Jul 2012, 05:47

Hello,

Thank you for such retailed and clear description. Try using:

Code: Select all
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} !^[^.]+\.(?:iddev|idqa|idlive).* [NC]
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]


Regards
Andrew

User avatar
Posts: 2
Joined: 25 Jul 2012, 04:42

Re: Non www to www but with some exceptions

25 Jul 2012, 06:39

Andrew, thank you so much, that amended rule works perfectly :)

Thanks for the quick response as well!

Tom

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 31 guests