3

Right now my domain www.example.com is setup to force HTTPS and it works. The site also correctly links everything to HTTPS. (there are no occurences of HTTP in the database anywhere).

But if you are visiting a subpage, you can change the url to HTTP again, for example http://example.com/subpage/ and it will not enforce HTTPS.

I have this rule in my .htaccess in the root:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

Any ideas what the cause of this is?

2 Answers 2

2

To globally redirect all your pages to HTTPS add the following lines to your .htaccess:

# Globally force SSL.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This should be placed directly after RewriteEngine on if you have no previous rewrites.

0

Try this htaccess rule

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
4
  • Don't forget to save permalinks after any rewrite rule change.
    – Junaid
    Jul 20, 2017 at 22:49
  • I've tried adding it and also replacing it with the previous code, neither works on subpages but thanks. edit: missed the permalinks thing, will try
    – Rizzah
    Jul 20, 2017 at 22:56
  • Same result after updating permalinks with that code and replacing that code. The mainpage works and links correctly to all https pages, but the subpages can be manually called as http and do not change to their https equivalent.
    – Rizzah
    Jul 20, 2017 at 22:58
  • Try this plugin, https://wordpress.org/plugins/wp-force-https/
    – Junaid
    Jul 20, 2017 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.