WordPress first page (index) is not secure (https), Force SSL

WordPress first page (index) is not secure (https), Force SSL

Force SSL:

Force redirect any website from http to https.

Problem statement:

I recently deployed my WordPress site and attached a valid SSL certificate, the surprising I see that all the pages of my site is showing secure padlock in the browser except landing or index page. It was terrible to trouble shoot it and took hours to figure out the root cause. Finally I broke it through and would like to share with you so it can help my readers in case they come across such situation.

Followings are the areas which you need to ensure are done from your end:

  • SSL Certificate: make sure your SSL certificate is valid and properly installed. I did my hosting in GoDaddy hence can give you reference which can be fond here
  • Database Update: make sure you have replaced your database contents from old url to new url by executing below update SQL commands:
UPDATE wp_options SET option_value = replace(option_value, 'http://yourOldSiteUrl.com', 'https://yourOldSiteUrl.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://yourOldSiteUrl.com','https://yourOldSiteUrl.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://yourOldSiteUrl.com', 'https://yourOldSiteUrl.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://yourOldSiteUrl.com','https://yourOldSiteUrl.com');
  • Root URL: make sure you access your WordPress Dashboard and visit General section under Settings where you change your Site url from http to https
  • Replace Post/contents: in WordPress install “Better Search and Replace” plugin and replace all old urls with new https url.
  • .htaccess: following script needs to be placed under .htaccess file to force redirect your site to https
RewriteEngine On
RewriteCond %{HTTP_HOST} yoursite\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Hope it will resolve your issue. Please don’t forget to put your valuable comments!!!

Leave a Reply

Your email address will not be published.