Httpd – RewriteRules in .htaccess in subdirectory disabling/breaking RewriteRules in .htaccess in parent directory

.htaccessapache-2.2drupalhttpdmod-rewrite

This is a shared hosting account with HostGator.

I've two .htaccess files.

One is in the document root: ~/public_html/.htaccess

# this is ~/public_html/.htaccess
## Redirect to https:// ##
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}/~myusername/$1 [R=301,L]

The other is in a subdirectory: ~/public_html/software/drupal-7.0/.htaccess. The contents of this .htaccess file can be found in the Drupal git.

The function of the .htaccess in the web root is to redirect all requests to https://. This works when I visit any URL except for those which are served from ~/public_html/software/drupal-7.0/.

I want my https:// redirection to work in ~/public_html/software/drupal-7.0/, as well, without modifying the .htaccess file which is in this directory.

Moving ~/public_html/software/drupal-7.0/.htaccess some place else seems to allow the https:// redirection to occur.

Why isn't my redirection occurring in URLs which are served from ~/public_html/software/drupal-7.0/, please?

Best Answer

RewriteOptions Inherit in the subdirectory's .htaccess file would cause the rules in the subdir to be evaluated, then the rules in the parent context.

If the Drupal rules make any changes, since this is per-directory context they will be sent back through the process a 2nd time and on the 2nd pass the canonical hostname rewrites will take effect.

Related Topic