tags:

views:

240

answers:

1

Basically I have a folder on my webserver that I assign to new domains whenever I buy them that only has an index.html and an images folder. It is basically just has my logo and says the domain is under construction and coming soon.

Normally when I want to force the www. prefix I use the following code:

rewritecond %{HTTP_HOST} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

This works fine however I need to explicitly write out the name of the domain. I deal with a lot of domains so I need code that will do this without knowing the domain name. I gave it a go but honestly got no one where close.

+1  A: 

Try this:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Gumbo