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:
Rewri开发者_开发问答teCond %{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?
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.
精彩评论