开发者

Mod_rewrite: How do I omit subdomains from rules?

开发者 https://www.devze.com 2022-12-16 09:33 出处:网络
Complete Apache newbie here. I\'m trying to get my main URL to redirect to the www. Here\'s the code I\'m using:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号