0

I'm going nuts here. Apache is completely ignoring both the RewriteCond and RewriteRule. I would expect this to error out as RewriteEngine has not been set to On. I had a bunch of other RewriteCond and RewriteRule lines that were working fine and when I checked the Rewrite log (I had enabled) it showed these two being skipped. I trimmed everything else to verify none of it was causing the issue, and sure enough, Apache happily proceeds nary an error with this configuration:

DocumentRoot /var/sites/public
<Directory /var/sites/public>
    AllowOverride None
    SetEnv APPLICATION_ENV production

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

    Order allow,deny
    allow from all
</Directory>

I'm pretty sure that there is some glaring error here that I've blinded myself to by staring at it for too long. Any help would be appreciated.

Notes: I don't have this in a Vhost. There aren't any Vhosts in the config. I've removed the RewriteCond and it still doesn't throw any errors. I have tried this with RewriteEngine On as well.

2 Answers 2

1

Just taking a quick look at it tells me that the RewriteCond won't match to anything except what appears to be nothing. Not sure how mod_rewrite feels about that.

What exactly are you trying to do with the rule?

For example, if you want it to match any domain but (www.)example.com and forward it to www.example.com, then you would have a rule like:

RewriteCond %{HTTP_HOST} !^(www.)?example\.com$
RewriteRule (.*) http://www.example.com/$1 [R,L]
1
  • Why wouldn't the RewriteCond match anything? As far as I read it, it says the HTTP_HOST isn't empty. It's straight from the docs.
    – coreyward
    Jun 21, 2010 at 13:42
0

You want this as well:

RewriteCond %{HTTP_HOST} .

...or written a different way:

RewriteCond %{HTTP_HOST}!=""

So:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .