Skip to content

Instantly share code, notes, and snippets.

@bocharsky-bw
Created June 19, 2014 10:10
Show Gist options
  • Save bocharsky-bw/3dc373b373275846b6de to your computer and use it in GitHub Desktop.
Save bocharsky-bw/3dc373b373275846b6de to your computer and use it in GitHub Desktop.
The .htaccess example for Symfony Framework project that deployed on shared hosting.
#path/to/project/.htaccess
# Rewrite all requests to subdirectory, except exists file requests
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>
#path/to/project/web/.htaccess
# Remove subdirectory and app.php file from request URI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(app\.php|app_dev\.php|config\.php|web/(?!app_dev\.php|config\.php))
RewriteRule ^(app\.php|app_dev\.php|config\.php)?/?(.*)$ /$2 [R=301,L]
</IfModule>
@raheelkhan
Copy link

Not working for me.. URL not found error

@walidos1993
Copy link

Work!!!! thank you very much

@azazqadir
Copy link

Going through all those scripts just to deploy symfony on shared hosting is quite a pain. I would recommend hosting PHP based apps, like symfony on a cloud server using PaaS, like Cloudways. This PHP MySQL web hosting platform lets users automatically setup server in one click. Once the server is ready, user can install Symfony using composer and deploy app from github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment