3

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.

James
  • 33
  • 3
  • Why do you mention /var/www/domain.name/project1/ when your aliasmatch will explicitly map to /var/www/domain.name/project1/public? – covener Aug 13 '15 at 23:07
  • @covener I was just giving a general idea of what I have setup. I've updated it to avoid confusion. Thanks! – James Aug 14 '15 at 00:27
  • "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 Aug 14 '15 at 21:07
  • @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 Aug 15 '15 at 13:26
  • And presumably you also enabled `Indexes`? Your `AliasMatch` directive maps _all_ URLs that _start_ `/projects/` to a single destination - is that intentional? Is `/var/www/domain.name//public` under the same document root? Add your `` to your question so we can have a better look. – MrWhite Aug 15 '15 at 16:20
  • @w3d Yeah, briefly, to see if it was actually pointing to the right directory. I'm not sure what you mean by a single destination; they all have they're own folder based on their name which is captured into `$1`. `domain.name/projects/ => /var/www/domain.name//public`, whereas `domain.name/projects/ => /var/www/domain.name/www/public` (essentially just accessing a php file in main site document root - I've stripped the .php extensions for files in the main site document root). I've added my VHost to the question. – James Aug 15 '15 at 18:07

1 Answers1

0

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
MrWhite
  • 43,179
  • 8
  • 60
  • 84