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:

  1. 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 at http://example.com instead of http://example.com/about
  2. 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.

1 Answer 1


The SSL admin and login redirection should be done through the FORCE_SSL_ADMIN constant in wp-config.php:

 define('FORCE_SSL_ADMIN', true);

For further information: Administration Over SSL

Aditionally, if you want be redirected to http when you're logged and in the frontend, take a look at:

Redirect WordPress front end https URLs to http without a plugin

Your Answer

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