Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Commit 3a4f0e7

Browse files
committed
fix redirect when project is installed in subdirectory
When neither a vhost with proper document root nor an apache alias is configured, the redirect was to the wrong location (without the path prefix). The context_prefix env variable was not available then, so we need to use the logic to determine the RewriteBase automatically as we have done it to resolve the app.php file too.
1 parent b66df19 commit 3a4f0e7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

web/.htaccess

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ DirectoryIndex app.php
88
<IfModule mod_rewrite.c>
99
RewriteEngine On
1010

11+
# Determine the RewriteBase automatically and set it as environment variable.
12+
# If you are using Apache aliases to do mass virtual hosting or installed the
13+
# project in a subdirectory, the base path will be prepended to allow proper
14+
# resolution of the app.php file and to redirect to the correct URI. It will
15+
# work in environments without path prefix as well, providing a safe, one-size
16+
# fits all solution. But as you do not need it in this case, you can comment
17+
# the following 2 lines to eliminate the overhead.
18+
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.+)::\2$
19+
RewriteRule ^(.*) - [E=BASE:%1]
20+
1121
# Redirect to URI without front controller to prevent duplicate content
1222
# (with and without `/app.php`). Only do this redirect on the initial
1323
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
@@ -20,21 +30,15 @@ DirectoryIndex app.php
2030
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
2131
# following RewriteCond (best solution)
2232
RewriteCond %{ENV:REDIRECT_STATUS} ^$
23-
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
33+
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
2434

2535
# If the requested filename exists, simply serve it.
2636
# We only want to let Apache serve files and not directories.
2737
RewriteCond %{REQUEST_FILENAME} -f
2838
RewriteRule .? - [L]
2939

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]
40+
# Rewrite all other queries to the front controller.
41+
RewriteRule .? %{ENV:BASE}/app.php [L]
3842
</IfModule>
3943

4044
<IfModule !mod_rewrite.c>

0 commit comments

Comments
 (0)