Which directories inherit an OVHcloud htaccess rule?

The Citead team, updated

In short. An OVHcloud .htaccess rule applies to its directory and descendants, while a child file can override higher-level directives.

Definition: On OVHcloud web hosting, rules in a .htaccess file apply to the directory that contains the file and to all of that directory's subdirectories. OVHcloud also instructs you to place only one .htaccess file in each directory or subdirectory.

Key facts

  • OVHcloud describes .htaccess as an Apache configuration file run by the web server of a Web Hosting plan, with rules for a directory and all its subdirectories. OVHcloud's operations guide states this scope.
  • You add the file in the directory for which you want the rules to apply. The rule then covers that directory and its descendants.
  • OVHcloud says to place only one .htaccess file per directory or subdirectory, to avoid conflicts between different .htaccess files.
  • Apache describes .htaccess as a distributed configuration file used on a per-directory basis. Its directives apply to the directory where the file is placed and all subdirectories. Apache's .htaccess tutorial documents this model.
  • Apache applies directives in directory order, so a .htaccess in a child directory may override directives found higher in the directory tree.

What is the inherited directory scope?

The scope starts with the directory containing the file. If the file is in /shop/, its rules apply to /shop/ and to paths below it, such as a product directory. A file in the site root therefore has a wider scope than a file in /shop/. OVHcloud's guide states that the rules apply to the entire directory where the file is installed and to all subdirectories in that same directory.

The rule is attached to a directory, rather than to a single URL. For example, this OVHcloud directive can be placed in a .htaccess file:

DirectoryIndex home.html

The same directory scope applies to that directive: the containing directory and its descendants are within the file's documented scope.

What changes when a child directory has its own file?

A child directory can have its own .htaccess file, provided it is a separate directory. Apache says that directives are applied in the order in which the files are found. A file in the child directory may override directives from files higher in the directory tree, and those higher files may themselves have overridden settings found still higher or in the main server configuration.

This layered behavior is different from placing two files in one directory. OVHcloud's operations guide says to place only one .htaccess file per directory or subdirectory. It also says that multiple .htaccess files can be created in the FTP space of the Web Hosting plan, which describes multiple files across the hosting space rather than multiple files in one directory.

How can you trace the boundary of a rule?

Start with the directory that contains the file, then inspect each descendant directory for a more specific .htaccess. Apache illustrates the lookup for a document under /www/htdocs/example with these possible files:

/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess

The Apache documentation says that the server looks in higher-level directories to assemble the applicable directives. On OVHcloud, the operations guide says the .htaccess file is invisible to website visitors, so the FTP space is the relevant place to inspect the files. The guide also identifies the FTP space as the place where you can create multiple .htaccess files.

FAQ

Does a .htaccess file in a parent directory apply to a child directory?

Yes. OVHcloud says the rules apply to the directory containing the file and all its subdirectories. Apache adds that a more specific file in the child directory may override directives from a higher-level file.

Can you place two .htaccess files in one OVHcloud directory?

No. OVHcloud instructs you to place only one .htaccess file per directory or subdirectory. Multiple files may exist in the FTP space when they are distributed across different directories.

Are all Apache directives accepted in .htaccess files?

Apache says that AllowOverride and AllowOverrideList determine which directives are permitted. Its documentation gives None as the default value for AllowOverride, under which .htaccess files are ignored unless they are enabled for a directory.

Sources

  1. OVHcloud, "Tutorial - Operations achievable with a .htaccess file", 23 May 2023
  2. Apache HTTP Server, "Apache HTTP Server Tutorial: .htaccess files", undated

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark