I\'m trying to use the [L]
flag in RewriteRule
, but it doesn\'t seem to work. I\'d like that if you call the page:
www.domain.com/admin
This isn't how L
works. The rewrite engine will continually loop through all the rules until the URI going into the engine is the same as the one coming out. The L
just tells the rewrite engine to stop applying rules in the current loop iteration. So say you have:
RewriteRule ^(.*)$ /foo/$1 [L]
RewriteRule ^(.*)$ /bar/$1 [L]
after 1 iteration, given the URI /blah
, I get /foo/blah
because it stops rewriting after the first rule (but will still continue to loop). If I remove the L
:
RewriteRule ^(.*)$ /foo/$1
RewriteRule ^(.*)$ /bar/$1
after 1 iteration, given the URI /blah
, I get /bar/foo/blah
. Both rules get applied, one after the other because the L
isn't there to stop it.
You need to add a condition in your second rule to prevent it from rewriting the first, either one of these will do:
RewriteCond $1 !^(backend\.php|index\.php|admin|assets|images|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
or:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond $1 !^(index\.php|admin|assets|images|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Your second rule is strange. I do not know what you are attempting to do by putting $1
as the value you are checking your condition against. It should probably look like this:
RewriteEngine on
RewriteRule ^admin/(.*) /backend.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !^(index\.php|admin|assets|images|uploads|robots\.txt|backend\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
Note I have also added a pass-through for backend.php