I'm struggling at getting these rewrite rules to work and was wondering if someone can point out my error(s).
The following should redirect a user to HTTPS if they are at the login page or in the admin dashboard. If they go anywhere else on the site, it should go back to HTTP.
# Redirect users to HTTPS when at the Login page or the Admin dashboard
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^\/Blog\/(wp-login.php) https://%{HTTP_HOST}/Blog/$1 [NC,R=301,L]
RewriteRule ^\/Blog\/wp-admin\/(.*) https://%{HTTP_HOST}/Blog/wp-admin/$1 [NC,R=301,L]
# Redirect users to HTTP when not at the Login page or Admin Dashboard
# Avoid loading mixed http/https content by excluding /wp-content/* and /wp-includes/*
RewriteEngine On
RewriteCond %{SERVER_PORT} !^80$
RewriteRule !^\/Blog\/(wp-login.php|wp-admin\/(.*)|wp-content\/(.*)|wp-includes\/(.*)) http://%{HTTP_HOST}/$1 [NC,R=301,L]
I'm a noob at this, so not sure if the above is correct. It seems to be working except in two scenarios:
- If I go to any page or post on my website as https instead of http, I get redirected to the main home page. For example: visit
https://example.com/about
and I end up athttp://example.com
instead ofhttp://example.com/about
- The Media Library of my admin dashboard loads over https, but does not show a padlock. I believe because it is accessing content at /wp-content/uploads over HTTP instead of HTTPS.
Just in case this is the problem, I also have these rewrite rules defined after the ones above:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Thanks in advance for any help you can provide.