0

I was actually wondering,

If I'd put a .htaccess in the /public_html folder and inside the /public_html/example_site/, would the pages inside /public_html/example_site/ use both of them?

And which of the two would be in favor, in case of conflicting arguments?

Use case
There are some rules I want to apply to every website I host, but there are some site-specific .htaccess rules. Therefor I would like to use two (or more) .htaccess files.

Sander Schaeffer
  • 2,757
  • 7
  • 28
  • 58
  • 1
    I'm unsure if you can use multiple .htacess files however you can certainly make rules that only target a single domain which would definately meet your use case – brendosthoughts Aug 31 '14 at 20:31

2 Answers2

1

.htaccess files apply to a directory and its subdirectories. “Deeper” ones have precedence over those which are higher in the directory structure.

By the way, if you have access to the Apache configuration itself, you should put directives there and disable .htaccess (AllowOverride None) completely. Otherwise, the webserver must scan each directory for a .htaccess file.

http://httpd.apache.org/docs/current/howto/htaccess.html

lxg
  • 12,375
  • 12
  • 51
  • 73
0

To answer your first question, if /public_html/example_site/.htaccess exists then it will take precedence over /public_html/.htaccess. If lower level .htaccess exists then directives in /public_html/.htaccess won't be used at all.

Now second question:

Use case There are some rules I want to apply to every website I host, but there are some site-specific .htaccess rules. Therefor I would like to use two (or more) .htaccess files.

If you want directives from parent .htaccess to be used then use:

RewriteOptions Inherit

But remember that rules inherited from the parent scope are applied after rules specified in the child scope.

anubhava
  • 761,203
  • 64
  • 569
  • 643