Redirect HTTP to HTTPS for WordPress

Md Riyazuddin Verified
Redirect the traffic on your WordPress site to the secured HTTPS protocol.

WordPress Preparation steps

These steps must be completed before altering any code.

  1. Log in to WordPress
  2. Choose the Settings on the left menu, then click on General..
  3. Look for the following entries within General settings:
    • WordPress Address (URL):
    • Site Address (URL):
  4. Update both URLs to include https rather than http.
  5. Make sure to save the modifications

Linux Redirect Steps

In the event that the WordPress website is located on Linux it will be using the .htaccess setting file. By putting your .htaccess in the root directory for your site can alter the behaviour of your website.

  1. Download the copy from your .htaccess from your hosting account.
  2. Open the file using your preferred text editor.

    NOTE:Make sure you edit the .htaccess file with an ordinary text editor that doesn't employ word wrap. Certain editors (such such as MS Word or Notepad with word wrap capabilities) can insert characters that are invisible to indicate the end of a line. Your .htaccess file won't work when it contains these particular characters.

  3. Make the necessary adjustments using the examples below.
  4. Save your modifications.
  5. Upload the altered .htaccess to your hosting account.
  6. Try to test your work by navigating normally to the site and it will redirect to HTTPS automatically.

Example WordPress .htaccess Content

Your WordPress website should already have an default entry within the .htaccess file. it should look like this example:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

To ensure that your hosting account is able to enforce the HTTPS protocol for all traffic that comes to the website, include the following in your .htaccess file.

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

You'll have to add the code snippet after the RewriteBase/ within the .htaccess file. It should be similar to this example:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Comments

Leave a Comment