Virtual host with rewrite does not execute .htaccess file. Used to work on Centos with Apache 2.2.

December 18, 2014 8.7k views


So I've just switch from another VPS provider to Digital Ocean and I'm loving it so far. Also with the switch I chose to switch from Centos 6 to Ubuntu 14. Very nice so far :)

But now I've run into a bit of a problem. The VPS is used as a development environment for multiple web developers.

Each developer has their own user and home directory:



But they are all hosted on the same domain. So i.e. a path to one of their projects could look like this:


This way each developer can have their own version of the same project hosted on the same domain :)

ANYWAY, here's my problem.

On our previous VPS I used the following vhost file:

<VirtualHost *:80>
        ServerAlias *

        # Set development environemnt variable
        SetEnv DEVELOPMENT true

        # Enable rewrite for dynamic developer environments
        RewriteEngine On

        # Dynamic developer environment
        RewriteCond %{HTTP_HOST} ^(.+)\.(.+)\$
        RewriteRule ^/(.*)$  /home/%1/sites/%2/$1  [L]

        # Enable .htaccess files
        <Directory />
                AllowOverride All

        # PHP Settings
        php_value error_reporting 30719
        php_value display_errors On
        php_value display_startup_errors On
        php_value post_max_size 100M
        php_value upload_max_filesize 100M

But now each developer gets a 403 forbidden file. The error.log shows the following message:

[Thu Dec 18 10:41:45.981506 2014] [autoindex:error] [pid 5527] [client] AH01276: Cannot serve directory /home/developer1/sites/projectname/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive

Also might be worth mentioning that our projects we develop are made with the Laravel framework. So each project lands on the root of the project. And in that root here's a .htaccess file that redirects each request to the /public/ folder. This is to avoid having /public/ appended to all the URL's in the project.

And it is THAT .htaccess file that doesn't get executed. We're never hitting the content of the /public/ folder.

I hope my question make sense and that some of you out there can help a brother out! :)

Merry Christmas and everything from
Morten / DuGi

  • Forgot to post the .htaccess file in my Laravel root. Might be something with that as well I guess. So here it is:

    RewriteEngine On
    # Set default rewrite base
    RewriteBase /public/
    # Usable directories with asset files
    RewriteRule ^images/(.*)$ images/$1 [L]
    RewriteRule ^css/(.*)$ css/$1 [L]
    RewriteRule ^js/(.*)$ js/$1 [L]
    RewriteRule ^fonts/(.*)$ fonts/$1 [L]
    RewriteRule ^resources/(.*)$ resources/$1 [L]
    # Otherwise redirect all other requests
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
  • have you checked/updated permissions for the web directory?

    sudo chown -R www-data:www-data /var/www

    also, not seeing a document root or directory set:

      DocumentRoot /var/www/theproject
        <Directory /var/www/theproject>
  • @sierracircle Yes, have set all those permissions on that folder :)

    But I don't believe I need a DocumentRoot? If I don't set one doesn't it fallback to default one? Also I cant' set a specific path in the <Directory /> because I'm doing RewriteRules inside the virtualhost.

    And like I'm saying, that EXACTLY piece code worked perfectly on Centos and Apache 2.2. Is there really big a difference between Centos and Ubuntu or Apache 2.2 and 2.4?

  • maybe just for ha-ha's create another config file and set the doc root and see what happens.

    Also, just to check (you probably already know this) I seem to remember that in Apache 2.2 your config file could be named whatever you want, but in Apache 2.4 it has to end in .conf

    so something like:

  • Did you find the solution? I'm having the same problem!

1 Answer
Have another answer? Share your knowledge.