Redirect HTTP to HTTPS for WordPress
WordPress Preparation steps
These steps must be completed before altering any code.
- Log in to WordPress
- Choose the Settings on the left menu, then click on General..
- Look for the following entries within General settings:
- WordPress Address (URL):
- Site Address (URL):
- Update both URLs to include https rather than http.
- Make sure to save the modifications
These steps must be completed before altering any code.
- Log in to WordPress
- Choose the Settings on the left menu, then click on General..
- Look for the following entries within General settings:
- WordPress Address (URL):
- Site Address (URL):
- Update both URLs to include https rather than http.
- 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.
- Download the copy from your
.htaccess
from your hosting account. - 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.
- Make the necessary adjustments using the examples below.
- Save your modifications.
- Upload the altered
.htaccess
to your hosting account. - Try to test your work by navigating normally to the site and it will redirect to HTTPS automatically.
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.
- Download the copy from your
.htaccess
from your hosting account. - 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.
- Make the necessary adjustments using the examples below.
- Save your modifications.
- Upload the altered
.htaccess
to your hosting account. - 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>
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