Search code examples
phpsymfonyroutesapache2.4mod-alias

symfony app_dev.php in folder outside document root


I'm renovating a legacy web app by replacing parts of it with Symfony.

My folder structure:

/symfony            <---symfony install
/trunk              <---document root

The document root is trunk/ so that changes to the legacy app are minimal.

In my Virtual Host Config I have:

<VirtualHost *:80>
    ServerName webapp.example.com

    DocumentRoot /path/to/project/trunk

    Alias /ajax ../symfony/web
    Alias /app_dev.php/ ../symfony/web/app_dev.php

</VirtualHost> 

A request to webapp.example.com/ajax works

However a request to webapp.example.com/app_dev.php/ajax leads to a 404 error.

Note I need to rewrite only paths that start with /app_dev.php/, ie. include the trailing slash.


Solution

  • According to http://httpd.apache.org/docs/2.4/mod/mod_alias.html#alias

    "Only complete path segments are matched"

    which means I cannot use Alias for rewriting the app_dev.php file.

    Instead Aliasmatch needs to be used. Also it does not seem to support relative paths, at least not on Apache 2.4.10, but I could not find any documentation of this.

    <VirtualHost *:80>
        ServerName webapp.example.com
    
        DocumentRoot /path/to/project/trunk
    
        Alias "/ajax" "../symfony/web"
        AliasMatch "^/app_dev.php/(.*)" "/path/to/project/symfony/web/app_dev.php/$1"
    
    </VirtualHost>