Configuring the ht.access file to force https

Hi there.
I recently switch to another server ( Centos8 and Plesk 18, php 7.3 and MariaDB 10.3 ).

I was using the code below previously:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*)$1 [R=301,L]

RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

But now I am getting error loops ( too many redirects ).

So I tried to use the ht.access file found in the latest version 2.7.3

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} (.+)$
RewriteRule ^(.*)$$1 [R=301,L] . 

And now, after deleting the cache, the website is in http and the manager is in https.
Any idea what I am doing wrong ? Thanks.

I don’t know the expressions well enough to tell you what you’re code is doing (or not doing in this case) but I use this simple code to redirect to https, maybe this helps:

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

Be sure to set the server_protocol System Setting to https if you haven’t already.

1 Like

Hi @vibedesign and @bobray , thanks for your replies.

I tried both solution, no luck there. It seems somehow modx if forcing http on the frontend, that is why every time I try to force https, I get a loop. ( Even after cleaning the cache manually ).

Do you know any other place you think I should look at? I’ve checked the setting, but I have found nothing related to the base url.

Make sure the server uses the right (updated) .htaccess file. Some hosts want you to manual refresh the file.

This works for me:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://{SERVER_NAME}/$1 R,L

1 Like

Some updates: Out of curiosity, I’ve installed wordpress just to check the default htaccess… and I am getting the same error loop… so it definitely comes from the server itself.

It may be a plugin, some settings that I have missed… the annoying part is that it is a fresh install of Centos8 and Plesk… frankly I have no idea where to look.

Wish me good luck :disappointed_relieved:

UPDATE: Found it! It’s actually an issue with cloudflare. See here:

1 Like

I’m glad you got it sorted. Thanks for reporting back. :slight_smile: