New Guy needs help

Topics: Developer Forum, User Forum
Aug 20, 2008 at 1:02 PM
Sorry if I should know this but can't find answer....

I want to rewrite [whatever.com] to [www.whatever.com]
Need this to handle any domain coming IN
#------------------------------------------------------------------------------------------------------
RewriteCond %{HTTP_HOST}  ^(?!www\.)WHATEVER\.com$   [I]
RewriteRule ^/(.*) http://www.WHATEVER.com/$1 [R=301] [I,L]
#------------------------------------------------------------------------------------------------------

***What I am using now***
Works but -- This list will keep growing, do not want a new rule for each domain
#------------------------------------------------------------------------------------------------------
RewriteCond %{HTTP_HOST}  ^(?!www\.)AAAAAA\.com$   [I]
RewriteRule ^/(.*) http://www.AAAAAA.com/$1 [R=301] [I,L]
#------------------------------------------------------------------------------------------------------
RewriteCond %{HTTP_HOST}  ^(?!www\.)BBBBBB\.com$   [I]
RewriteRule ^/(.*) http://www.BBBBBB.com/$1 [R=301] [I,L]
#------------------------------------------------------------------------------------------------------
RewriteCond %{HTTP_HOST}  ^(?!www\.)CCCCCC\.com$   [I]
RewriteRule ^/(.*) http://www.CCCCCC.com/$1 [R=301] [I,L]
#------------------------------------------------------------------------------------------------------

Thanks for any help,
David


Coordinator
Aug 21, 2008 at 12:18 AM

Try this?

 #------------------------------------------------------------------------------------------------------
RewriteCond %{HTTP_HOST}  ^(?!www\.)([^.]+)\.com$   [I]
RewriteRule ^/(.*) http://www.%1.com/$1 [R=301] [I,L]
#------------------------------------------------------------------------------------------------------ 
 

you can play with the ([^.]+) - for example if you want to allow dots in that section (eg, if ZZZ.AAAA.com should get mapped to www.ZZZ.AAAA.com, then you would want to change that segment to (.+). The former says "any series of characters that does not include a dot" and the latter says "a series of any characters".