0

I'm currently working on a Symfony2 application that, for the time being, has to be hosted inside a subdirectory. Normally one would change the DocumentRoot in the Apache vhost but this is currently not possible. It's also not possible to place anything in the root directory (e.g. above public_html/).

The DocumentRoot is set at /public_html/. The structure with the Symfony2 app in a subdirectory looks like this:

- public_html/
-- dev/
---- app/
---- bin/
---- src/
---- vendor/
---- web/

Without any special configuration the app can be reached at http://example.com/dev/web/app.php. I however want to change this to http://example.com/dev without having to move files around.

I came up with the following .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_URI} !dev/web/
RewriteRule (.*) /dev/web/app.php/$1 [L]

This kinda works, but Symfony2 reports the following error: No route found for "GET /dev/".

If I change the RewriteRule to RewriteRule (.*) /dev/web/$1 [L] I can reach the app with http://example.com/dev/app.php/dashboard (dashboard being an example of course) which results in No route found for "GET hboard", notice hboard. Calling http://example.com/dev/app.php/ does render the page at / perfectly and links to all assets work fine as well.

Any help would be much appreciated. In time this app has to move from dev/ to / as well. So a solution for that is welcome as well.

Htbaa
  • 2,319
  • 18
  • 28

1 Answers1

1

The default web/.htaccess file from Symfony2 looks like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

You should add dev/web/ before app.php and move it to your root directory.

EDIT:

After some research I found this answer on SO. So the new .htaccess should be like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?!dev/web/).*)$ dev/web/app.php [QSA,L]
</IfModule>

Also look at

Community
  • 1
  • 1
ferdynator
  • 6,245
  • 3
  • 27
  • 56
  • As stated in the question I can't change the DocumentRoot. – Htbaa Oct 01 '13 at 18:05
  • Sorry I misread the question. Updated my answer. I hope this is more helpful. – ferdynator Oct 01 '13 at 18:14
  • This still results in the error `No route found for "GET /dev/dashboard"` or `"GET /dev/"` for `/`. – Htbaa Oct 01 '13 at 18:22
  • Updated Answer again. – ferdynator Oct 01 '13 at 20:34
  • Is it the root directory e.g. public_html or public_html/dev where I need to put the .htaccess? I've already tried the latter but that didn't give the desired results. Looking at the paths I guess it should be in public_html? – Htbaa Oct 01 '13 at 21:09
  • I decided to move everything up into the root directory. All I've got to do now is that stuff from the bundles/ directory will be server, but that's just a simple rewrite away. – Htbaa Oct 02 '13 at 08:09