Installing symfony in a subdirectory of your documentroot

I recently needed to set up a Symfony install without a separate virtual host, so as a subdirectory of the (Apache) DocumentRoot directory (like:

As you may know, symfony appreciates it when it has a reserved virtual host for itself, but also provides ways to just install it in a separate directory. The following steps need to be taken:

1. Change the apps/<yourapp>/config/settings.yml file and set relative_url_root

    relative_url_root: /subdir

2. Go to your front controller’s .htaccess file (usually in web/) and modify the RewriteBase directive

RewriteBase /subdir/

3. Optionally, if you want to omit the script name in production environment url’s, be sure to have enabled no_script_name = on in apps/<yourapp>/config/settings.yml

    no_script_name: on

4. If you took step 3, be sure to check if your apache installation has support for mod_rewrite enabled.

This way you can have nice url’s, like http://www.example/subdir/module/action
That’s it!

4 responses to “Installing symfony in a subdirectory of your documentroot”

  1. Dudes, can u put the put content of you .htaccess?

    I fallow your instruction and still no luck for me.

    Here is my .htaccess content

    Options +FollowSymLinks +ExecCGI

    RewriteEngine On

    # uncomment the following line, if you are having trouble
    # getting no_script_name to work
    RewriteBase /testing/

    # we skip all files with .something
    #RewriteCond %{REQUEST_URI} \..+$
    #RewriteCond %{REQUEST_URI} !\.html$
    #RewriteRule .* – [L]

    # we check if the .html version is here (caching)
    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f

    # no, so we redirect to our front web controller
    RewriteRule ^(.*)$ index.php [QSA,L]


  2. Hi! I followed your guide, however Apache returns me a 403 error, saying “Forbidden – You don’t have permission to access /symfony/ on this server”.
    Can you post here your *external* (httpd root directory) .htaccess?
    Thank you in advance,

  3. Hi Paolo, does the apache user and group (usually www-data or nobody) has read rights on the symfony directory in your web root?

    Try accessing /symfony/index.php directly and see if that works.

  4. There is no index.php inside of /symfony (this is the name of the subfolder).
    However I put a test.php file and it says “Internal Server Error”. Apache logs say “Directory index forbidden by Options directive: /web/htdocs/