I want everything to be redirected to index.php, so I thought this should work:
RewriteEngine on
RewriteRule ^(.*)$ /index.php?url=$1 [L]
..but it doesn’t. This very similar RewriteRule does work though:
RewriteEngine on
RewriteRule matches/(.*) /index.php?url=$1 [L]
I later found out that to make the first one work you need:
RewriteCond %{REQUEST_FILENAME} !-f
Can someone please explain why the last RewriteCond is needed in the former example but not the latter?
Because first rule will rewrite already rewritten URL.
RewriteRule Last [L] flag not working?
For example:
/hello/pink-kitten/index.php?url=hello/pink-kitten/index.php?url=index.php/index.php?url=index.phpWhy rule works if added that condition? Because the condition clearly says — only do rewrite if requested URL is not file. Therefore, on 2nd cycle URL will not be rewritten again as
/index.phpis a file, therefore no more cycles.Why 2nd rule works just like that? Because it already has condition built in — URL should contain
matches/in it, and rewritten URL/index.php?url=as you can see has nomatches/part in it.