简体   繁体   中英

apache directory index behaviour

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM