.htaccess is ignored even though VirtualHost has “AllowOverride All”

.htaccessapache-2.2virtualhost

I'm running a LAMP server on Fedora 13 that's working fine; however, I just added an ".htaccess" file to my current site's docroot folder that is being completely ignored.

I've tried half a dozen different tests, including this one:

RewriteEngine on
RewriteBase /

RewriteRule ^.*$ index.php

But images and all other pages load fine, and non-existent files still 404. I also tried this:

order deny,allow
deny from all

But every page still loads just fine. Again the .htaccess file is simply ignored 100%.

We put our virtualhost records in /etc/httpd/conf.d/virtual.conf. It looks like this:

NameVirtualHost *

<VirtualHost *>
    ServerName              intranet
    DocumentRoot            /var/www/default
    <Directory "/var/www/default">
        Options FollowSymLinks
        AllowOverride All

        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *>
    ServerName              ourwebsite.com
    DocumentRoot            /var/www/html/ourwebsite.com/docroot
    <Directory "/var/www/html/ourwebsite.com/docroot">
        Options FollowSymLinks
        AllowOverride All

        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

What else could be causing our server to completely IGNORE the .htaccess file??

Edit:

I changed the .htaccess file to above to better demonstrate that my changes are being ignored. Note that I tried the exact same .htaccess file on the production server and it worked fine.

Edit 2:

OK, I have new information! Just for testing purposes, I went through and temporarily changed EVERY "AllowOverride" directive to AllowOverride All. I figured out that the very first Directory entry seems to overpower all others:

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

When I changed that to AllowOverride All, my .htaccess files begin taking effect. It's like all the other AllowOverride All directives in my config files are being ignored!

What Gives??

Best Answer

Unbelievable. Remember how I said this is a development server? Yeah.. well here's what my virtual host entry REALLY looks like:

<VirtualHost *>
    ServerName              dev.ourwebsite.com
    DocumentRoot            /var/www/html/dev.ourwebsite.com/docroot
    <Directory "/var/www/html/ourwebsite.com/docroot">
        Options FollowSymLinks
        AllowOverride All

        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Do you see it? Well I didn't. I FORGOT To change my "Directory" entry to dev.ourwebsite.com instead of ourwebsite.com -- and that made all the difference. I just assumed that Apache would have thrown an error if the directory didn't exist; but that only applies to the DocumentRoot directive. is match-based -- meaning it applies the rules if it matches the incoming request, but otherwise, it doesn't care if you tell it to AllowOverride on magic unicorns.

Let this be a lesson to any others who come looking -- when all else fails, consider the almighty Typo.

Related Topic