| Htaccess for multiple Domains redirecting non-www to www |
Cirilo007

msg:3836138 | 1:08 am on Jan 28, 2009 (gmt 0) | Hi apache gurus, Let's say that you got 30 domain names pointing to 1 IP address and that you want to redirect all the non-www versions of your domains to their www versions. Now let's suppose that you are very lazy, and that you don't want to add the *classical* redirect code for each domain but try to automatize it and say that by default, no matter the domain name, automatically redirect it to his www version... Is it just a dream or there is hope ? Here is what I'd like to avoid : RewriteCond %{HTTP_HOST} !^www.domain1.com$ [NC] RewriteRule ^(.*)$ http://www.domain1.com/$1 [r=301,L] RewriteCond %{HTTP_HOST} !^www.domain2.com$ [NC] RewriteRule ^(.*)$ http://www.domain2.com/$1 [r=301,L] ... RewriteCond %{HTTP_HOST} !^www.domain30.com$ [NC] RewriteRule ^(.*)$ http://www.domain30.com/$1 [r=301,L] Let me know your thoughts ! Thanks in advance
|
smallcompany

msg:3836254 | 6:53 am on Jan 28, 2009 (gmt 0) | # canonicalize all non-www domain variants RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^([a-z0-9][a-z0-9\-]*[a-z0-9]\.(co\.[a-z]{2}¦[a-z]{2,6}))\.?(:[0-9]{1,5})?$ [NC] RewriteRule (.*) [%1...] [R=301,L] # # canonicalize all www domain variants RewriteCond %{HTTP_HOST} ^www\.([a-z0-9][a-z0-9\-]*[a-z0-9]\.(co\.[a-z]{2}¦[a-z]{2,6}))(\.¦\.?:[0-9]{1,5})$ [NC] RewriteRule (.*) [%1...] [R=301,L] The above is "made by Jim". [webmasterworld.com...] Replace the broken pipe "¦" characters in all code above with solid pipes before use.
|
Cirilo007

msg:3836514 | 2:49 pm on Jan 28, 2009 (gmt 0) | Worked like a charm ! Thanks a lot, you saved me a lot of headaches !
|
|
|