1

I upgraded my Ubuntu to 14.04 LTS and Apache to 2.4. When the server first started back up I was getting 403 errors visiting pages. This is when I learned I needed to change to Require all granted. I thought I had everything working till I realized .htaccess was not being loaded anywhere. I thought that needed to be changed as well, but the Apache docs says it's fine from what I can find. Below is my Directory rule currently.

VirtualDocumentRoot /var/hosts/%-2.0.%-1.0/%-3+/public_html
<DirectoryMatch "^/var/hosts/[^/]+/[^/]+/public_html">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</DirectoryMatch>

My first thought was the regex was wrong and none of the rules were being loaded. So I commented out the Require all granted and saw it stopped websites from loading again. So I knew it was loading them. I had to do the below to get them to work.

<Directory /var/hosts/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Am I ok to leave it with this? Any thoughts why it isn't working?

2 Answers 2

0

Try this:

  1. Configure Apache mod_rewrite

    a2enmod rewrite
    
  2. add the following code to /etc/apache2/sites-available/default

    AllowOverride All 
    
  3. Restart Apache

    /etc/init.d/apache2 restart
    
4
  • That module is already enabled and I already have AllowOverride All in my default. That's the first <DirectoryMatch> above.
    – John
    Commented Jan 14, 2015 at 15:35
  • How did you make .htaccess file? ( if windows id you convert or save correct) who has access to the file? any error in logs? Commented Jan 16, 2015 at 20:04
  • The .htaccess files worked before I upgraded. I noticed websites that used them, it was being ignored. So I modified one so that it should throw a 500 error. I didn't get the expected result till I added the over arching <Directory /var/hosts/>. So I don't see it as a permission issue. I couldn't find any errors in the logs.
    – John
    Commented Jan 16, 2015 at 20:08
  • what is in .htaccess file? Commented Jan 16, 2015 at 20:13
0

I solved my issue.

It seems Apache 2.4 has issues with [^/]+ to match a directory. I was able to make it work with * instead. It matches everything but a /.

I had come across this issue again with trying to secure any subdomain of dev. I saw that specifying the domain instead of using REGEX would work within the VirtualHost.

After looking over the Directory docs I learned about * and gave it a shot. Also learned that DirectoryMatch does not affect subdirectories and that Directory allows REGEX.

1
  • "Apache 2.4 has issues with [^/]+" - Hhhm, no it doesn't? Do you have a reference? It does if you are using a vanilla <Directory> directive (that accepts wildcards only). But a <DirectoryMatch> directives (as stated in the question) takes a regex.
    – MrWhite
    Commented Sep 3, 2020 at 22:08

You must log in to answer this question.

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