29

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,093
  • 4
  • 15
  • 23

4 Answers4

41

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,093
  • 4
  • 15
  • 23
  • I never in a million years would have caught this! I also had a typo in the Directory path, also a dev project... Thanks for opening my eyes. – gillytech Dec 07 '14 at 05:33
  • I too had a typo in the directory portion. Really, this was so frustrating. It was a blessing that I came accross this and came to know of the fact that I can make super silly mistakes. – Akash Kumar Sharma Apr 04 '16 at 13:10
  • I know it's been 7 years, but I just wanted to pop in and say this answer just helped me. It was the same type of thing. I had copied directives from a different virtual host and changed the wrong bit. Thanks for sharing this info! Surf Wisely. – dolst Jan 07 '17 at 17:06
5

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

Denis
  • 473
  • 3
  • 9
  • The server I'm working with is a development server, and it's an exact duplicate of our production server. The httpd.conf files are practically identical. The ONLY significant difference is that our "virtual.conf" on this server has fewer entries and each site is prefixed with `dev.`. Yet the production server works fine, .htaccess files behave precisely as expected, and the development server simply ignores the .htaccess file altogether. – Brian Lacy Nov 23 '10 at 16:20
1

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
  • 208
  • 1
  • 7
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
  • 17,764
  • 2
  • 30
  • 47
  • I'm not getting 500 errors. The .htaccess file is simply ignored. And I verified that I did not have a space in there anyway. I know nothing about selinux or contexts, but I looked up how to check and apparently it's Disabled. As for `AccessFileName`, I'll look around, but as I said in my comment on Denis' answer, the apache configuration for these two servers is effectively identical. – Brian Lacy Nov 23 '10 at 16:30
  • I've also had issues with the space. It drove me crazy. – egorgry Nov 23 '10 at 16:32
  • Whoops, correction: I DO have an AccessFileName directive in my httpd.conf. It reads as follows: `AccessFileName .htaccess` – Brian Lacy Nov 23 '10 at 16:36