HTTPS htaccess redirection with multiple htaccess file problem

Hi, I can’t solve an issue so I’m asking for help here.

Let’s say I have with the forced HTTPS redirection for any request.

Then in I have some rewriterule rules regarding that specific folder.

Problem is that HTTPS redirection on that folder doesn’t work anymore and I can access it both from HTTP and from HTTPS.

If I remove the rules (which I need) the HTTPS redirection works again.

I’ve searched the new a long time for a solution but didn’t find one. Anyone knows what to do?

Thanks in advance!

it’s hard to tell without seeing what each individual .htaccess specifies. Apache applies the .htaccess rules in the order they’re found. So a directive in might negate one that is in

You may want to read Apache HTTP Server Tutorial: .htaccess files and especially How directives are applied. If you’re still confused, share the content of your .htaccess.

Thanks for the answer. I’ve created a test case to try solutions without affecting production site.

So I have with this code:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Then I have with:

RewriteEngine  on
RewriteRule page([0-9]+)\.php /test/page.php?id=$1 [L]

If I access I’m redirected to BUT if I access or, I get correct result but without HTTPS redirection.

I then discovered that if I add the HTTPS redirection rules from main folder .htaccess also to the subfolder one, redirection works again. But is this the correct way to do it? And exactly why the subfolder htaccess overrides HTTPS redirection? Isn’t it executed after the first one?

The Apache tutorial says that Rewrite Rules in .htaccess files make things different… You may want to explicitly make /test/.htaccess inherit from previous directory using RewriteOptions Directive. Check for details.

Have you tried just making the redirect absolute?

RewriteRule page([0-9]+)\.php$1 [L]

Thanks, interesting option! Sadly as we still don’t have Apache 2.4 on DH, it’s useless as inherited rules are executed AFTER local ones. Will be handy when DH finally update Apache and we will get options InheritBefore and InheritDown.

So for now I’ve just to copy the https redirection rules. Good to know this is the way. Thanks again!

1 Like

It doesn’t solve problem for other pages (including index) in

I think you can force the inherit by putting this at top of the htaccess in the sub directory:

RewriteRule inherit
1 Like

The description for the option is really confusing, then, because… I tried and it works! Thank you all.

1 Like

You’re welcome… glad it’s working.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.