For those of you who run Wordpress using SSL (https://www), and you have been having issues with your website, here’s a quick fix.

This guide will enable you to redirect all of the following combinations:

http://www.domain.com

http://www.domain.com/subdir

http://domain.com

http://domain.com/subdir

www.domain.com

www.domain.com/subdir

domain.com

domain.com/sub

For me, all of the following had to be activated to achieve for a fully functioning website:

 

1. Updating your .htaccess file

I used the following in my HTACCESS:

 

# BEGIN WordPress

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

 

 2. Changing WordPress Functions.php

My setup is much more modular so I don’t have this in my functions.php. However, for example purposes I’ve written and you can try it:

 

/* Force SSL */
function force_ssl () {
	
  if ( !is_ssl() ) {
    $request = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    wp_redirect( $request, 301 );
    exit();
  }
  
}

add_action( 'template_redirect', 'force_ssl', 1 );

/* Update siteurl and home url */
update_option('siteurl','https://' . $_SERVER['HTTP_HOST']); 
update_option('home','https://' . $_SERVER['HTTP_HOST']);

 



View More Tutorials

See more posts on tutorials.

Wordpress, PHP, JavaScript, jQuery, CSS, HTML, MYSQL and more!

Categorised As:Tutorials
COMMENTS