1
votes

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.

2

2 Answers

1
votes

EDIT

This is the link to the apache documentation http://httpd.apache.org/docs/2.4/mod/mod_alias.html#alias

The problem seems to be the trailing slash in the end of the second Alias directive

Try changing this:

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

to this:

Alias "/app_dev.php" "../symfony/web/app_dev.php"

From the docs:

Note that if you include a trailing / on the URL-path then the server will require a trailing / in order to expand the alias. That is, if you use

Alias "/icons/" "/usr/local/apache/icons/"
then the URL /icons will not be aliased, as it lacks that trailing /. Likewise, if you omit the slash on the URL-path then you must also omit it from the file-path.

Another option

If that doesn't work, try removing the second Alias directive, as you are already pointing to the symfony/web folder with the /ajax URL path.

0
votes

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>