.htaccess 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Use the front controller as index file. It serves as a 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. # start page (path "/") because otherwise Apache will apply the rewriting 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. # Determine the RewriteBase automatically and set it as environment variable.
  10. # If you are using Apache aliases to do mass virtual hosting or installed the
  11. # project in a subdirectory, the base path will be prepended to allow proper
  12. # resolution of the app.php file and to redirect to the correct URI. It will
  13. # work in environments without path prefix as well, providing a safe, one-size
  14. # fits all solution. But as you do not need it in this case, you can comment
  15. # the following 2 lines to eliminate the overhead.
  16. RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
  17. RewriteRule ^(.*) - [E=BASE:%1]
  18. # Redirect to URI without front controller to prevent duplicate content
  19. # (with and without `/app.php`). Only do this redirect on the initial
  20. # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
  21. # endless redirect loop (request -> rewrite to front controller ->
  22. # redirect -> request -> ...).
  23. # So in case you get a "too many redirects" error or you always get redirected
  24. # to the start page because your Apache does not expose the REDIRECT_STATUS
  25. # environment variable, you have 2 choices:
  26. # - disable this feature by commenting the following 2 lines or
  27. # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
  28. # following RewriteCond (best solution)
  29. RewriteCond %{ENV:REDIRECT_STATUS} ^$
  30. RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=302,L]
  31. # If the requested filename exists, simply serve it.
  32. # We only want to let Apache serve files and not directories.
  33. RewriteCond %{REQUEST_FILENAME} -f
  34. RewriteRule .? - [L]
  35. # Ignore symfony files
  36. RewriteRule ^(assetic)($|/) - [L]
  37. RewriteRule ^(assets)($|/) - [L]
  38. RewriteRule ^(css)($|/) - [L]
  39. RewriteRule ^(fonts)($|/) - [L]
  40. RewriteRule ^(upload)($|/) - [L]
  41. # Rewrite all other queries to the front controller.
  42. RewriteRule .? %{ENV:BASE}/app.php [L]
  43. </IfModule>
  44. <IfModule !mod_rewrite.c>
  45. <IfModule mod_alias.c>
  46. # When mod_rewrite is not available, we instruct a temporary redirect of
  47. # the start page to the front controller explicitly so that the website
  48. # and the generated links can still be used.
  49. RedirectMatch 302 ^/$ /app.php/
  50. # RedirectTemp cannot be used instead
  51. </IfModule>
  52. </IfModule>