|
| 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 |
| - # 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 |
8 |
| - |
9 | 11 | # Redirect to URI without front controller to prevent duplicate content
|
10 | 12 | # (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 |
| 13 | + # rewrite by Apache and not on subsequent cycles. Otherwise we would get an |
12 | 14 | # endless redirect loop (request -> rewrite to front controller ->
|
13 | 15 | # 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 | + # 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: |
16 | 19 | # - 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 |
| 20 | + # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the |
18 | 21 | # following RewriteCond (best solution)
|
19 | 22 | RewriteCond %{ENV:REDIRECT_STATUS} ^$
|
20 | 23 | RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
|
21 | 24 |
|
22 | 25 | # If the requested filename exists, simply serve it.
|
23 |
| - # We only want to let apache serve files and not directories. |
| 26 | + # We only want to let Apache serve files and not directories. |
24 | 27 | RewriteCond %{REQUEST_FILENAME} -f
|
25 | 28 | RewriteRule .? - [L]
|
26 | 29 |
|
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. |
| 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. |
33 | 35 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
|
34 | 36 | RewriteRule ^(.*) - [E=BASE:%1]
|
35 | 37 | RewriteRule .? %{ENV:BASE}app.php [L]
|
36 | 38 | </IfModule>
|
| 39 | + |
| 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> |
| 48 | +</IfModule> |
0 commit comments