Created
April 17, 2013 20:15
-
-
Save michaelhagedon/5407378 to your computer and use it in GitHub Desktop.
A modified Symfony2 .htaccess file that makes it possible to set the front controller from the Apache virtual host (kind of like Rails).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| ### Call the correct front controller. This is dependent on an environment variable being set | |
| ### in the virtual host configuration. SetEnv seems not to work, so here's an example with SetEnvIfNoCase: | |
| ### <Directory /path/to/application/web> | |
| ### SetEnvIfNoCase REQUEST_URI .* SYMFONY_ENV=dev | |
| ### </Directory> | |
| ### This will force the following rules to call the dev front controller. | |
| # Make sure the prod front controller is called without a suffix. | |
| # (prod OR production) and file doesn't exist | |
| RewriteCond %{ENV:SYMFONY_ENV} prod [OR] | |
| RewriteCond %{ENV:SYMFONY_ENV} production | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^(.*)$ app.php [QSA,L] | |
| # dev | |
| RewriteCond %{ENV:SYMFONY_ENV} dev [OR] | |
| RewriteCond %{ENV:SYMFONY_ENV} development | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^(.*)$ app_dev.php [QSA,L] | |
| # any other front controller | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{ENV:SYMFONY_ENV} ^(.+)$ | |
| RewriteRule ^(.*)$ app_%1.php [QSA,L] | |
| # Default to prod if there is no variable set (most secure) | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^(.*)$ app.php [QSA,L] | |
| </IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment