Jump to content

Force WWW on multiple sites


cmgmyr

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,

-Chris

Link to comment
https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.