3
votes

From the documentation I have this:

AliasMatch "^/projects/(.+)" "/var/www/domain.name/$1/public"

It should match only URLs like ../projects/project1, not ../projects/ by itself.

When I go to say, http://example.org/projects/project1/ it returns a 403 Forbidden.The logs say because of:

No matching DirectoryIndex found, and server-generated directory index forbidden by Options directive.

I've tried adding a DirectoryIndex explicitly in the vhosts but to no avail. I opened up the directory (/var/www/domain.name/project1/public) to be readable by everyone and now it just shows a directory listing of the folder I want. I can see that its going to the right folder and can see the index.html file but it just doesn't automatically get it like it should.


Summarized version of my VirtualHost file:
<VirtualHost *:443>
    DocumentRoot /var/www/domain.name/www/public
    ServerName www.domain.name

    AliasMatch "^/projects/(.+)" "/var/www/domain.name/$1/public"

    ErrorDocument 401 err.php
    ErrorDocument 404 err.php
    ErrorDocument 500 err.php

    <Directory /var/www/domain.name>
        Options Indexes FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

If I then set the permissions on the specific project folder to 755 I just get a directory listing. I've changed it back to 711.

All folders in /var/www/ are owned by username:www-data and have the permissions 711.

If I do a direct Alias to the folder i.e. Alias /projects/<actual-project-name> /var/www/domain.name/<project-name>/public it works.

1
Why do you mention /var/www/domain.name/project1/ when your aliasmatch will explicitly map to /var/www/domain.name/project1/public? - covener
@covener I was just giving a general idea of what I have setup. I've updated it to avoid confusion. Thanks! - James
"No matching DirectoryIndex found" - means that you don't have an index.html (or whatever the specified directory index file is) in that directory. - MrWhite
@w3d "...now it just shows a directory listing of the folder I want. I can see that its going to the right folder and can see the index.html file...". Everything is fine except it doesn't fetch the index file thats there, instead it just displays a directory listing (in which I can see the index file). - James
And presumably you also enabled Indexes? Your AliasMatch directive maps all URLs that start /projects/<project> to a single destination - is that intentional? Is /var/www/domain.name/<project>/public under the same document root? Add your <VirtualHost> to your question so we can have a better look. - MrWhite

1 Answers

0
votes

AliasMatch "^/projects/(.+)" "/var/www/domain.name/$1/public"

The problem with this is that all requests are mapped to a single URL - a directory. AliasMatch does not copy the trailing path onto the end of the target, unlike an Alias.

When you request /projects/project1, the alias naturally maps you to /projects/public. mod_dir (DirectorySlash) appends a trailing slash (since this is a valid directory), but the directory index is lost. The target file is literally just /projects/public/ (a directory), as stated in the AliasMatch directive, not /projects/public/index.html as would seem to be required.

To make this work as intended (to be able to access all files within the "public" directory, eg. index.php) then you need a 2nd parenthesised subpattern, something like:

AliasMatch ^/projects/([^/]+)(.*) /var/www/domain.name/$1/public/$2