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/
it redirects you to:
www.domain.com/backend.php
Otherwise, if you call any other page (except for some pages) it redirects to:
www.domain.com/index.php
Here is what I have so far:
RewriteEngine on
RewriteRule ^admin/(.*) /backend.php/$1 [L]
RewriteCond $1 !^(index\.php|admin|assets|images|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
If I use only the first rule, it works (but obviously doesn’t redirect other pages to index.php). If I add the second rule, the server seems to ignore the first rule (I think it is “overwritten” by the second rule, even if I added the [L] flag)
This isn’t how
Lworks. 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. TheLjust tells the rewrite engine to stop applying rules in the current loop iteration. So say you have:after 1 iteration, given the URI
/blah, I get/foo/blahbecause it stops rewriting after the first rule (but will still continue to loop). If I remove theL:after 1 iteration, given the URI
/blah, I get/bar/foo/blah. Both rules get applied, one after the other because theLisn’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:
or: