1
+ # For a symfony application to work properly, you MUST store this .htaccess in
2
+ # the same directory as your front controller, index.php, in a standard symfony
3
+ # web application is under the "public" project subdirectory.
4
+
5
+ # Use the front controller as index file.
6
+ DirectoryIndex index.php
7
+
8
+ # Uncomment the following line if you install assets as symlinks or if you
9
+ # experience problems related to symlinks when compiling LESS/Sass/CoffeScript.
10
+ # Options +FollowSymlinks
11
+
12
+ # Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
13
+ # to the front controller "/index.php" but be rewritten to "/index.php/index".
14
+ <IfModule mod_negotiation.c >
15
+ Options -MultiViews
16
+ </IfModule >
17
+
18
+ <IfModule mod_rewrite.c >
19
+ RewriteEngine On
20
+
21
+ # This RewriteRule is used to dynamically discover the RewriteBase path.
22
+ # See https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
23
+ # Here we will compare the stripped per-dir path *relative to the filesystem
24
+ # path where the .htaccess file is read from* with the URI of the request.
25
+ #
26
+ # If a match is found, the prefix path is stored into an ENV var that is later
27
+ # used to properly prefix the URI of the front controller index.php.
28
+ # This is what makes it possible to host a Symfony application under a subpath,
29
+ # such as example.com/subpath
30
+
31
+ # The convoluted rewrite condition means:
32
+ # 1. Match all current URI in the RewriteRule and backreference it using $0
33
+ # 2. Strip the request uri the per-dir path and use ir as REQUEST_URI.
34
+ # This is documented in https://bit.ly/3zDm3SI ("What is matched?")
35
+ # 3. Evaluate the RewriteCond, assuming your DocumentRoot is /var/www/html,
36
+ # this .htaccess is in the /var/www/html/public dir and your request URI
37
+ # is /public/hello/world:
38
+ # * strip per-dir prefix: /var/www/html/public/hello/world -> hello/world
39
+ # * applying pattern '.*' to uri 'hello/world'
40
+ # * RewriteCond: input='/public/hello/world::hello/world' pattern='^(/.+)/(.*)::\\2$' => matched
41
+ # 4. Execute the RewriteRule:
42
+ # * The %1 in the RewriteRule flag E=BASE:%1 refers to the first group captured in the RewriteCond ^(/.+)/(.*)
43
+ # * setting env variable 'BASE' to '/public'
44
+ RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
45
+ RewriteRule .* - [E=BASE:%1 ]
46
+
47
+ # Sets the HTTP_AUTHORIZATION header removed by Apache
48
+ RewriteCond %{HTTP:Authorization} .+
49
+ RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0 ]
50
+
51
+ # Removes the /index.php/ part from a URL, if present
52
+ RewriteCond %{ENV:REDIRECT_STATUS} =""
53
+ RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301 ,L]
54
+
55
+ # If the requested filename exists, simply serve it.
56
+ # Otherwise rewrite all other queries to the front controller.
57
+ RewriteCond %{REQUEST_FILENAME} !-f
58
+ RewriteRule ^ %{ENV:BASE}/index.php [L]
59
+ </IfModule >
60
+
61
+ <IfModule !mod_rewrite.c >
62
+ <IfModule mod_alias.c >
63
+ # When mod_rewrite is not available, we instruct a temporary redirect
64
+ # to the front controller explicitly so that the website
65
+ RedirectMatch 307 ^/$ /index.php/
66
+ </IfModule >
67
+ </IfModule >
0 commit comments