Jump to content

Force WWW on multiple sites


Recommended Posts

Hello everyone,

I have a site where any number of other domains can point to it. Right now I just have:

RewriteCond %{HTTP_HOST} ^domain.com [NC] 
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

Which obviously just works for domain.com how can I adjust this so it forces the redirect for any domain that comes through?


Thanks in advance,


Link to comment
Share on other sites

For a finite number of sub-domains you could use something like...


RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} !^admin\. [NC]
RewriteCond %{HTTP_HOST} !^members\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]


Or if all your domains are in the same TLD...


RewriteCond %{HTTP_HOST} ^[^.]+.com [NC] 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]


Depending on what domains you are working with will depend on what is the best solution.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.