Last Updated: February 25, 2016
·
3.957K
· fredylg

Redirect on .htaccess to index.php running twice

I was doing some work and I found that my insert queries were running twice only on Chrome which is quite unusual, usually to redirect all traffic to index I just go like :

RewriteEngine on

if a directory or a file exists, use it directly

RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUEST
FILENAME} !-d

otherwise forward it to index.php

RewriteRule ^(.*) index.php?url=$1 [L,QSA]

But if you try to access an index file it fallis into the folder rule and then by default hits the index.
For some reason Firefox does not request the file but just follows the redirect. After some testing I found out that this behaviour can be abolished if the redirect is done like this:

RewriteEngine on
RewriteCond $1 !^(index.php|robots.txt|favicon.ico) #and so on..
RewriteRule ^(.*)$ /index.php/$1 [L]

Has anyone found a better way? let me know!

Cheers