views:

15

answers:

1

Complete Apache newbie here. I'm trying to get my main URL to redirect to the www. Here's the code I'm using:

RewriteCond %{HTTP_HOST} !^www\.domain\.com 
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L] 

The problem is, this has wrecked my subdomains. sub.domain.com goes to www.sub.domain.com, which doesn't work. So what do I write to fix that?

+1  A: 

This might be enough:

RewriteCond %{HTTP_HOST} ^domain\.com 
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]

If all you're trying to do is make domain.com go to www.domain.com, then just use a RewriteCond that only matches domain.com at the start.

Ry4an