简体   繁体   中英

Order that apache process rules in htaccess

I have a very complex directory structure in this server I am working and lots of htaccess on multilevel. I know apache merges the configurations from all htaccess but it's not that easy as it sounds...

For example, if an htaccess file close to the root makes use of "Filesmatch" to set configurations, then if I try to change those same configurations in another htaccess file on a deeper directory without using "Filesmatch" the configurations are not changed. I realized I can only change them if I use Filesmatch ".*".

I think I know why: apache processes some things first and others later despite the order they are placed inside an htaccess file.

So I would like to know this: is there a solid documentation where I can see clearly what apache processes first and what later? I mean, even in the same htaccess files some rules "dont look" to work in the exact order they appear inside the file cause somethings are probably executed in a different order.

Asking this question to Apache community they provided me the answer very easily! It's here: https://httpd.apache.org/docs/2.4/sections.html#merging

The configuration sections are applied in a very particular order. Since this can have important effects on how configuration directives are interpreted, it is important to understand how this works. The configuration sections are applied in a very particular order. Since this can have important effects on how configuration directives are interpreted, it is important to understand how this works.

The order of merging is:

  • <Directory> (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding <Directory> )
  • <DirectoryMatch> (and <Directory "~"> )
  • <Files> and <FilesMatch> done simultaneously
  • <Location> and <LocationMatch> done simultaneously
  • <If>

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