From 0b38dbbb62500bb78e4028cce8b5e2d3786d7054 Mon Sep 17 00:00:00 2001 From: Sandeep Shetty Date: Sun, 4 May 2014 01:12:40 +0530 Subject: [PATCH 1/4] Fix RewriteRule for subdirectory installation The current rule didn't work under a subdirectory for me (I'm not using Zend, just the .htaccess rules for an app of mine). Fix based on: https://github.com/symfony/symfony-standard/blob/680f09b76dd01355a92a209d1926bf54b7aa50f7/web/.htaccess#L18 Thanks @Tobion and @weierophinney for this gem. --- public/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/.htaccess b/public/.htaccess index de2cf3f86e..9007df1694 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -11,6 +11,6 @@ RewriteRule ^.*$ - [NC,L] # allow proper resolution of the index.php file; it will work # in non-aliased environments as well, providing a safe, one-size # fits all solution. -RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ +RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1] RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] From 22776a9ec7780aa51b2e7fdcd1d7ba91ecd6e7e8 Mon Sep 17 00:00:00 2001 From: Sandeep Shetty Date: Sun, 4 May 2014 17:34:56 +0530 Subject: [PATCH 2/4] Fixed bug and updated comments. --- public/.htaccess | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/.htaccess b/public/.htaccess index 9007df1694..4f38f19157 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -7,10 +7,10 @@ RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] # The following rewrites all other queries to index.php. The # condition ensures that if you are using Apache aliases to do -# mass virtual hosting, the base path will be prepended to -# allow proper resolution of the index.php file; it will work -# in non-aliased environments as well, providing a safe, one-size -# fits all solution. +# mass virtual hosting or installed the project in a subdirectory, +# the base path will be prepended to allow proper resolution of +# the index.php file; it will work in non-aliased environments +# as well, providing a safe, one-size fits all solution. RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1] -RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] +RewriteRule ^(.*)$ %{ENV:BASE}/index.php [NC,L] From 0148c8771f9a6f9f26045abcac08092a670a0d50 Mon Sep 17 00:00:00 2001 From: Sandeep Shetty Date: Sun, 4 May 2014 23:54:50 +0530 Subject: [PATCH 3/4] NC flag is not required and last rules doesn't require L flag There are no literals in the pattern that requires case insensitivity and the L flag on the last rule is redundant IIUC. --- public/.htaccess | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/.htaccess b/public/.htaccess index 4f38f19157..70ab7e247e 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -4,7 +4,7 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d -RewriteRule ^.*$ - [NC,L] +RewriteRule ^.*$ - [L] # The following rewrites all other queries to index.php. The # condition ensures that if you are using Apache aliases to do # mass virtual hosting or installed the project in a subdirectory, @@ -13,4 +13,4 @@ RewriteRule ^.*$ - [NC,L] # as well, providing a safe, one-size fits all solution. RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1] -RewriteRule ^(.*)$ %{ENV:BASE}/index.php [NC,L] +RewriteRule ^(.*)$ %{ENV:BASE}/index.php From 5647699bfd50eb166eba3d849549f6717af8a7ae Mon Sep 17 00:00:00 2001 From: Sandeep Shetty Date: Tue, 6 May 2014 02:17:24 +0530 Subject: [PATCH 4/4] Added the last L back In case developers add custom rules after this. See https://github.com/symfony/symfony-standard/pull/656 --- public/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/.htaccess b/public/.htaccess index 70ab7e247e..99b80df14f 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -13,4 +13,4 @@ RewriteRule ^.*$ - [L] # as well, providing a safe, one-size fits all solution. RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1] -RewriteRule ^(.*)$ %{ENV:BASE}/index.php +RewriteRule ^(.*)$ %{ENV:BASE}/index.php [L]