.htaccess 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. <IfModule mod_rewrite.c>
  8. RewriteEngine On
  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 or you always get redirected
  15. # to the startpage because your Apache does not expose the REDIRECT_STATUS
  16. # environment variable, you have 2 choices:
  17. # - disable this feature by commenting the following 2 lines or
  18. # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
  19. # following RewriteCond (best solution)
  20. RewriteCond %{ENV:REDIRECT_STATUS} ^$
  21. RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
  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. # The following rewrites all other queries to the front controller. The
  27. # condition ensures that if you are using Apache aliases to do mass virtual
  28. # hosting, the base path will be prepended to allow proper resolution of the
  29. # app.php file; it will work in non-aliased environments as well, providing
  30. # a safe, one-size fits all solution.
  31. RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
  32. RewriteRule ^(.*) - [E=BASE:%1]
  33. RewriteRule .? %{ENV:BASE}app.php [L]
  34. </IfModule>
  35. <IfModule !mod_rewrite.c>
  36. <IfModule mod_alias.c>
  37. # When mod_rewrite is not available, we instruct a temporary redirect of
  38. # the startpage to the front controller explicitly so that the website
  39. # and the generated links can still be used.
  40. RedirectMatch 302 ^/$ /app.php/
  41. # RedirectTemp cannot be used instead
  42. </IfModule>
  43. </IfModule>