Question

i have a .htacces file containing

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?action=$1 [QSA,L]

it suits my need well. Accidentaly once i erased out the filename condiion like so

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?action=$1 [QSA,L]

to my ill understanding apache grabed the default file (index.html or index.php depending on setup) and inserted that into the action varible can someone plese explain to my how that works as its clearly not the route taken when the line is present.

Was it helpful?

Solution

The reason is because the -f checks if the request file exists. On top of that, the rewrite engine will loop through all the rules until the URI stops changing. That means the first time around, say you have the request URI: /foo/bar

  • it's not a directory
  • it matches ^(.*)
  • URI gets rewritten to index.php?action=foo/bar

next time around, the URI is /index.php

  • it's not a directory
  • it matches ^(.*)
  • URI gets rewritten to index.php?action=index.php

next time around, it doesn't change so rewriting stops.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top