Posting this to SE instead of ServerFault since it has a focus on web development and includes references to Symfony.
I'm having trouble creating a .htaccess rewrite with Symfony's default .htaccess setup. My intention is as follows:
- Internally rewrite all requests to
bla/something/*
tosomething/else
. something/else
is not a valid file in the webroot, but rather a URI handled by the Symfony application- request flow thus becomes: match internal rewrite, re-process the rules with
something/else
(which is then rewritten - and found by the Symfony app), thus serving thesomething/else
controller while the browser's URL still showsbla/something/x
.
I've build the following basic rule which works when used for 301 redirects:
RewriteRule ^bla/something/(.+)$ /something/else
thus resulting in the full .htaccess file being:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
# RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# DirectoryIndex index.php
# RewriteCond %{ENV:REDIRECT_STATUS} ^$
# RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteRule ^bla/something/(.+)$ /something/else
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
# RewriteRule ^ %{ENV:BASE}/index.php [L]
FallbackResource /index.php
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
Ideally, all that I've commented out should be enabled and working. I've just tried to distill it down to the most basic file. What else have I tried:
Flags: [PT], [L]…
Replacing with 301 redirects: those work, so the rule matches
rule order
The problem is however, that the request is not rewritten at all internally. Browser shows /bla/something/x
, which is also what the Symfony application sees for the requested path.