cmgmyr Posted June 27, 2010 Share Posted June 27, 2010 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 More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 RewriteCond %{HTTP_HOST} !^www. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] Link to comment https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/#findComment-1078069 Share on other sites More sharing options...
cmgmyr Posted June 28, 2010 Author Share Posted June 28, 2010 Thanks, worked great! Link to comment https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/#findComment-1078250 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 Just as a word of warning, this will mess-up if you have any subdomains as it will also redirect http://subdomain.domain.com to http://www.subdomain.domain.com. Link to comment https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/#findComment-1078252 Share on other sites More sharing options...
cmgmyr Posted June 28, 2010 Author Share Posted June 28, 2010 Oh, that's not so great. Is there a way to exclude some sub domains? I'm only using a few of them so it would be easy to manually update. Link to comment https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/#findComment-1078253 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 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 https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/#findComment-1078257 Share on other sites More sharing options...
cmgmyr Posted June 28, 2010 Author Share Posted June 28, 2010 Got it, thanks again! Link to comment https://forums.phpfreaks.com/topic/205985-force-www-on-multiple-sites/#findComment-1078271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.