1

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?

MrWhite
  • 12,647
  • 4
  • 29
  • 41

1 Answers1

2

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.

MrWhite
  • 12,647
  • 4
  • 29
  • 41
covener
  • 1,685
  • 9
  • 15
  • The combination of directories not inheriting rewrite rules by default and the necessity of the directive which enables inheritance to be in the child and not the parent means that I have to modify the .htaccess file supplied by Drupal. It is meant to be edited, though, so I guess that this is OK. – Shahar 'Dawn' Or May 02 '11 at 15:52
  • 1
    An added complication with mod_rewrite inheritance is that the directives are effectively copied in-place into the subdirectory's `.htaccess` file. This means that the directives might not even work the same as when used in the parent directory - which is the case with the HTTP to HTTPS redirect in the question. These directives are unlikely to work without modification, due to the capturing backreference from the `RewriteRule` _pattern_. The use of the `REQUEST_URI` server variable might be required instead. There are now more "inheritance" options available with Apache 2.4. – MrWhite Aug 10 '20 at 00:09