Redirect WordPress to HTTPS using htaccess

In order to redirect your website to HTTPS using WWW or non-WWW, you can use this guide to edit your WordPress website’s htaccess file accordingly.

Redirect to HTTPS WWW/non-WWW

Edit your WordPress htaccess file and add the following code to the top of your file, whilst keeping the other code below.

HTTPS without WWW

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]


RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]

Which redirection to use

The type of redirection you use depends on your requirements, as it can be set to personal preference or optimised for better SEO results.

Best redirection for SEO

  1. If the domain had a previous website – match the old variation of WWW or non-WWW.
  2. If the domain is fresh and you’ve simply forgotten to redirect the website – Google your website and use whichever version shows up in the search results.

Additional tips

  1. If you’re struggling to open your htaccess file through an FTP, you can use Yoast SEO to open and edit this through the WordPress admin area.
  2. When you come to check if the redirection has been successfully implemented, you should use a private browser session to show uncached results.