HTTPS Force Redirect not working in Wordpress HTTPS Force Redirect not working in Wordpress wordpress wordpress

HTTPS Force Redirect not working in Wordpress


Change the order of the rules. First redirect to https and then let WP take over all of your requests.

<IfModule mod_rewrite.c>RewriteEngine OnRewriteCond %{HTTPS} offRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]RewriteBase /blog/RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /blog/index.php [L]</IfModule>


You can also add these two lines to the wp-config.php

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);

So you could easily make conditions for http for dev environment and https for live like so:

if(strpos($_SERVER['HTTP_HOST'], 'livedomain.com') !== FALSE){  define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);  define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);} else {  define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);  define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);}