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