30

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??

Brian Lacy
  • 1,123
  • 4
  • 16
  • 23

5 Answers5

42

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.

Brian Lacy
  • 1,123
  • 4
  • 16
  • 23
5

Check out if any other "AllowOverride None" presented in 'httpd.conf' above the virtualhosts declaration. Probably, you have "AllowOverride None" in docroot.

Denis
  • 463
2

I had this on a fresh server, eventually realised that mod-rewrite wasn't enabled by default.

ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
jmullee
  • 248
0

In my case, the .htaccess file wasn't readable by the apache user.

I solved it with

chown ubuntu:www-data .htaccess
chmod 750 .htaccess
0

Three guesses:

Is there actually a space after the comma in the line order deny, allow in .htaccess? Apache doesn't like that. For me on F13 I was get 500s.

Do you have a AccessFileName directive anywhere?

If you are using selinux do you have the correct context for the file (ls -lZ)?

Mark Wagner
  • 18,428