Symfony2 .htaccess to redirect request from /web to /


Symfony2 HTACCESS file to remove 'web' folder from url

Defaul url http://mydomain.com/web/action
Wanted url  http://mydomain.com/action

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^/web/app_dev.php - [L]
    RewriteRule ^/web/app.php - [L]

    # Fix the bundles folder
    RewriteRule ^bundles/(.*)$ /web/bundles/$1  [QSA,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    # Change below before deploying to production
    #RewriteRule ^(.*)$ /web/app.php [QSA,L]
    RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>

save configuration above to .htaccess and save it to your project root folder 

3 thoughts on “Symfony2 .htaccess to redirect request from /web to /

  1. Hi Yoesoff,
    why are you actually getting the `web` prefix in your url?
    I guess you pointed your document root of your virtual host to the main symfony2 folder including all the other folders like `app` and àpp/config`. This is a security issue because all these files including your config files should not be available to public.
    You need to set your document root to the `web` folder and everything will work out fine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s