Apache 2.2 ignoring rewrite rules within .htaccess files unless it is located within the default website directory


We are experiencing a strange problem on our development Apache 2.2 web server.  The default htdocs directory is /www/htdocs, and rewrite rules are processed fine if they reside within a .htaccess file inside that directory, however, when that file is moved to a virtual host, the rewrite rules are not processed, but the .htaccess file is still read as I can cause a 500 error if I put jargon into it and the errordocs are honoured where they have been set.

From this, I'm pretty sure that it is not a fault in the rewrite rules themselves, so it must lie within the httpd.conf file.  I have attached the config files to this post, though identifying domains and email addresses have been replaced with valid placeholders.

If anyone has any idea what could be causing this issue, I would be very grateful.

Thanks in advance,


Edited to add: I'm not a beginner, but there doesn't seem to be any way to change that field after this has been submitted, so more fool me for not filling it out properly in the first place. ;)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add the 'RewriteEngine On' in each virtual host section, then restart apache.


"Note that rewrite configurations are not inherited by virtual hosts. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use rewrite rules."

IllaraneAuthor Commented:

I tried that and it still won't honour the RewriteRule directives.  The top of the .htaccess file looks like this:

RewriteEngine On
RewriteBase /

Additionally, I get the following appearing in the RewriteLog when I browse to http://www.mydomain.com/login/, which is rewritten to /index.php?page=login: - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9cf83b8/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/login - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d54eb8/initial/redir#1] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/index.php - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9cfc3c8/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/themes/default/css/theme.css - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9cf83b8/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/include - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d56d10/initial/redir#1] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/index.php - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9cf83b8/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/favicon.ico - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d51348/initial/redir#1] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/index.php - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d033e0/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/mysite - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d5c680/initial/redir#1] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/index.php - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d073f0/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/mysite - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d03920/initial/redir#1] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/index.php - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d0b400/initial] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/mysite - - [08/Feb/2008:16:10:44 +0000] [dev.mydomain.com/sid#9b24868][rid#9d7aef0/initial/redir#1] (1) [per-dir /www/vhosts/dev.mydomain.com/httpdocs/] pass through /www/vhosts/dev.mydomain.com/httpdocs/index.php

Also, adding RewriteEngine On to the VirtualHost section seems to stop my RewriteLog from working... :/

Now, from your logs and your config I see that your .htaccess rewrite rule work.
It's taken from /www/vhosts/dev.sagazone.co.uk/httpdocs/.htaccess
and _not_ from /www/htdocs/.htaccess

dev.mydomain.com is your default virtual host, because it is your first virtualhost section, it serves all names that don't match ServerName in any other virtualhost.
Directory /www/htdocs is never used for 'document root' because you have enabled NameVirtualHost and defined at least one VirtualHost entry. So www.mydomain.com is also served by dev.mydomain.com virtual domain section.

Read more here:

So your .htaccess is from /www/vhosts/dev.sagazone.co.uk/httpdocs/,
thats the point.

Next, why do I say the rewrite engine is working? Because we see all these entries in your rewrite log. I see lots of 'pass through', that means that nothing has been rewritten.

If you think that some rules doesn't work, you should show all that rules, not only the top of the .htaccess.

Once you have defined 'RewriteEngine On' in a VirtualHost section you should place RewriteLog there as well. The same is for RewriteLogLevel.

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

IllaraneAuthor Commented:

The .htaccess file is exactly the same.  If I remove the virtual hosts include from http.conf and put everything in /www/htdocs, it all works fine, but if I enable the virtual hosts and move everything into one of the virtual hosts folders, nothing gets rewritten at all.  The URLs haven't changed, I'm not moving it to something like http://dev.mydomain.com/folder/; it just stops working, so I'm pretty certain that it's not an issue with the .htaccess file.
IllaraneAuthor Commented:
Turns out it was the / on the front of the rewrite checks.  Took this out, and it works fine everywhere now.
Hi, Illaran.

Let me disagree with your last comment.

You were asked to provide full .htaccess config with rewrite rules:
>> If you think that some rules doesn't work, you should show all that rules, not only the top of the .htaccess.

Then you say that it's ok and didn't post .htaccess:
> The .htaccess file is exactly the same.

Now you say that your rewrite checks contain leading '/'
> Turns out it was the / on the front of the rewrite checks.  Took this out, and it works fine everywhere now.

So your last solution about PAQ-ing the question is not much useful for others, because they can't see the reason of why it was not working as intended (because they don't see your .htaccess file here and can't guess what was wrong with it).

For PAQing, I guess that's enough to post your .htaccess (or even one line from it) before and after the change.
IllaraneAuthor Commented:
The rewrite rules looked something like this before:

RewriteRule ^/rewrite/this/to/? /index.php?page=rewrite&mode=this&id=to [QSA,L]

and this after:

RewriteRule ^rewrite/this/to/? /index.php?page=rewrite&mode=this&id=to [QSA,L]

For some reason, Apache interprets the / on the front of the rewrite rule to mean the default htdocs directory as defined within the configuration, not the root of the current virtual host, hence the confusion as to why it worked before from within that directory but not anywhere else.

Removing the / made it all work.

I'd attach the .htdocs files to this comment, but I don't have them to hand.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OK, now I agree that you provided all info to mark this question as PAQ.
Closed, 250 points refunded.
EE Moderator
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.