|
1 | 1 | <IfModule mod_rewrite.c>
|
2 | 2 | RewriteEngine On
|
3 | 3 |
|
4 |
| - #<IfModule mod_vhost_alias.c> |
5 |
| - # RewriteBase / |
6 |
| - #</IfModule> |
| 4 | + # This reduces the matching process for the startpage (path "/") because |
| 5 | + # otherwise apache will apply the rewritting rules to each configured |
| 6 | + # DirectoryIndex file needlessly (e.g. index.php, index.html, index.pl). |
| 7 | + DirectoryIndex |
7 | 8 |
|
8 |
| - RewriteCond %{REQUEST_FILENAME} !-f |
9 |
| - RewriteRule ^(.*)$ app.php [QSA,L] |
| 9 | + # Redirect to URI without front controller to prevent duplicate content |
| 10 | + # (with and without `/app.php`). Only do this redirect on the initial |
| 11 | + # rewrite by apache and not on subsequent cycles. Otherwise we would get an |
| 12 | + # endless redirect loop (request -> rewrite to front controller -> |
| 13 | + # redirect -> request -> ...). |
| 14 | + # So in case you get a "too many redirects" error because your apache does |
| 15 | + # not expose the REDIRECT_STATUS environment variable, you have 2 choices: |
| 16 | + # - disable this feature by commenting the following 2 lines or |
| 17 | + # - use apache >= 2.3.9 and replace all L flags by END flags and remove the |
| 18 | + # following RewriteCond (best solution) |
| 19 | + RewriteCond %{ENV:REDIRECT_STATUS} ^$ |
| 20 | + RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L] |
| 21 | + |
| 22 | + # If the requested filename exists, simply serve it. |
| 23 | + # We only want to let apache serve files and not directories. |
| 24 | + RewriteCond %{REQUEST_FILENAME} -f |
| 25 | + RewriteRule .? - [L] |
| 26 | + |
| 27 | + # The following rewrites all other queries to app.php. The |
| 28 | + # condition ensures that if you are using Apache aliases to do |
| 29 | + # mass virtual hosting, the base path will be prepended to |
| 30 | + # allow proper resolution of the app.php file; it will work |
| 31 | + # in non-aliased environments as well, providing a safe, one-size |
| 32 | + # fits all solution. |
| 33 | + RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ |
| 34 | + RewriteRule ^(.*) - [E=BASE:%1] |
| 35 | + RewriteRule .? %{ENV:BASE}app.php [L] |
10 | 36 | </IfModule>
|
0 commit comments