apache.htaccesserrordocument

Which ErrorDocument request will take precedence?


I have a domain which contains within it multiple sites with multiple .htaccess files (it's for clients to check their own projects out before they go live to their own servers, so each .htaccess file controls its own site).

If I have a .htaccess file in the root, it will control the domain. If mydomain.com/doesntexist is entered and it doesn't exist, the root's 404 page will come up. If mydomain.com/doesexist/doesntexist is entered, the .htaccess file in the "doesexist" directory would take priority, as opposed to the root's .htaccess file ... correct?


Solution

  • You are correct.
    I suggest you to read Apache HTTP Server Tutorial: .htaccess files

    The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.


    ROOT htaccess

    ErrorDocument 404 /index.php
    

    subfolder htaccess

    ErrorDocument 404 /subfolder/index.php
    

    http://domain.com/does_not_exist --> (404 error) /index.php
    http://domain.com/subfolder/does_not_exist --> (404 error) /subfolder/index.php