views:

243

answers:

2

I want any request to http://example.com/* to be redirected to http://www.example.com/*.

Where * is any arbitrary path.

+3  A: 

Use Apache's mod_alias module to do a permanent redirect like:

RedirectPermanent / "http://www.example.com/"

Place the redirect inside the blank subdomain's virtualhost block or root level .htaccess file.

The trailing / on "http://www.example.com/" is crucial.

nutcracker
A: 

I'll add another option here that I've used to allow for other specific hosts as well. For example if you wanted a dev.example.com and a blog.example.com site in addition to your www.example.com site, put this in your root level .htaccess file:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^dev\.example\.com
RewriteCond %{HTTP_HOST} !^blog\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L,QSA]
Eric Petroelje