.htaccess AWS PHP Ubuntu Wordpress

How to fix WordPress HTTPS issues when behind an Amazon Load Balancer?

Pinterest LinkedIn Tumblr

Use this 4 step method to remove the redirect loop and mixed content problems when using ssl in WordPress.

1) Replace ‘http://’ with ‘//’ in database – This create all the relative url’s for images and other assets

2) in wp-config, define generic wp_home and wp_siteurl variables.

define('WP_HOME','//'. $_SERVER['SERVER_NAME']);
define('WP_SITEURL','//'. $_SERVER['SERVER_NAME']);

3) If you are using a load balancer, use ‘HTTP_X_FORWARDED_PROTO’ server variable to figure out the protocol used. To do this, add this line in wp-config

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

4) Finally, in .htaccess, use this line if you are behind load balancer to redirect all traffic to https.

 # http to https
 RewriteCond %{HTTP:X-Forwarded-Proto} =http
 RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

Write A Comment