Rory
Rory

Reputation: 1

Mod_rewrite: How do I omit subdomains from rules?

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?

Upvotes: 0

Views: 66

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78350

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.

Upvotes: 1

Related Questions