Redirect HTTP to HTTPS for WordPress on Linux
To redirect your WordPress website to the secure HTTPS protocol on Linux, there are several steps that need to be taken before the redirect will work properly.
Note: If your site is hosted on our Managed WordPress hosting platform you do not need to manually change these settings, the HTTPS protocol will be configured automatically.
WordPress Preparation steps
These steps should be taken before modifying any code.
- Log in to WordPress
- Select Settings from the menu and click on General.
- Locate the following entries in the General settings::
- WordPress Address (URL):
- Site Address (URL):
- Update both URLS to include https instead of http
- Save the changes
Linux Redirect Steps
If your WordPress website is hosted on Linux, it will use an .htaccess configuration file. Placing the .htaccess
in the root folder for your site will change the behavior of your site.
- Download a copy of your
.htaccess
from your hosting account. - Open the file with your favorite text editor
Note: Make sure you edit the .htaccess file using a plain text editor that doesn't use word wrap. Some editors (such as MS Word or Notepad with word wrap enabled) will insert invisible characters to signify a line break. Your .htaccess file will not work if it has these special characters in it.
- Make the necessary changes using the examples below.
- Save your changes.
- Upload the modified
.htaccess
to your hosting account. - Test your work by navigating normally to the web site, and it should redirect to HTTPS automatically.
Example WordPress .htaccess Content
Your WordPress site should already have a default entry in your .htaccess
file. it should look similar to 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 your hosting account will force the HTTPS protocol on all traffic to the site, you'll need to add the following to the .htaccess file.
RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You'll need to place the code snippet after the RewriteBase /
in the .htaccess
file. It should look similar to the following 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>