Understanding htaccess and how rules affect sub-directories

My understanding was that a local .htaccess file (within the current directory) would override a .htaccess in a parent directory?

This does not seem to be the case and therefore I am hoping to seek a better understanding of the process and how it cascades.

Read More

I have a website in /public_html with a .htaccess

# BEGIN Domain Redirects
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Then, I created a sub-directory at /public_html/testing.example.com and within there I implemented it’s own .htaccess as follows:

# BEGIN Domain Redirects
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !testing.example.com$ [NC]
RewriteRule ^(.*)$ http://testing.example.com/$1 [L,R=301]

My expectation is that when I access http://testing.example.com the domain will always remain http://testing.example.com because /public_html/testing.example.com/.htaccess would be the master directives file?

And this sort of works… Until I try to install WordPress… When I get to step 3 and click “Run the Install”, the URL changes to http://www.example.com/testing.example.com/ and it throws an error.

Forbidden

You don’t have permission to access /wp-admin/install.php on this
server.

Additionally, a 403 Forbidden error was encountered while trying to
use an ErrorDocument to handle the request.

To get around this now, I have to rename /public_html/.htaccess temporarily while I run an install on the sub-directory and then change it back after completion.

Is this normal behaviour? Am I wrong in assuming that the sub-directory /public_html/testing.example.com/.htaccess should be the master when accessing http://testing.example.com/?

Related posts