SSL certificate works only on index page

I installed my SSL certificate. Then I followed the instructions to force users to visit https and not http. So I created an .htaccess file in my root directory and inserted this

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:CF-Visitor} !{"scheme": "https"}
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301].

The problem is that only the index page appears to have a secure connection, while the others do not.

This is an example of how my website is structured.

Immagine 2022-04-17 161019

Could the problem be that the other files are in folders other than the .htaccess file, which cannot reach them?
If so, how can I solve it?

Try this instead:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

And then instead of using htaccess to redirect CloudFlare to https, just enable automatic https rewrites.

3 Likes

.htaccess rule automatically apply to subdirectories as well. However, subdirectories can have their own .htaccess files which override the .htaccess directives in the parent directory.

Do the sub folders have their own .htaccess file? And do those files contain the RewriteEngine On line? If so, please delete it, because the RewriteEngine On removes all previously configured rewrite rules, which includes the HTTPS redirect rules you’re trying to set for the entire site.

2 Likes

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