Ensuring that your WordPress website uses HTTPS instead of HTTP is crucial for security, SEO rankings, and user trust. This guide walks you through the preparation steps for transitioning to HTTPS, including updating WordPress settings and configuring your .htaccess file on a Linux server.
Step 1: Update WordPress General Settings
Before making any code changes, start by updating your WordPress settings to reflect the use of HTTPS.
- Log in to Your WordPress Dashboard
- Use your WordPress admin credentials to access the dashboard.
- Navigate to General Settings
- From the WordPress menu, go to Settings and click on General.
- Update the URL Fields
- Locate the following fields in the General settings:
- WordPress Address (URL)
- Site Address (URL)
- Replace
httpwithhttpsin both fields.
- Locate the following fields in the General settings:
- Save Changes
- Scroll down and click the Save Changes button to apply the new settings.
Step 2: Configure the .htaccess File on Linux
If your WordPress site is hosted on a Linux server, you’ll need to edit the .htaccess file to enforce HTTPS on all traffic.
What is the .htaccess File?
The .htaccess file is a configuration file used by web servers like Apache to control website behavior. For WordPress, it helps manage permalinks, redirects, and other server-level settings.
How to Edit the .htaccess File
- Download the
.htaccessFile- Access your hosting account’s file manager or use an FTP client.
- Locate the
.htaccessfile in the root directory of your WordPress installation and download a backup copy.
- Open the File in a Text Editor
- Use a plain text editor like Notepad++ or Sublime Text. Avoid word processors like MS Word to prevent adding unwanted characters.
- Add HTTPS Redirect Rules
- Locate the line
RewriteBase /in the.htaccessfile. - Add the following code immediately after it to redirect all traffic to HTTPS:
RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
- Locate the line
- Save Your Changes
- Save the updated
.htaccessfile on your computer.
- Save the updated
- Upload the Modified File
- Use your hosting account’s file manager or FTP client to upload the modified
.htaccessfile back to the root directory of your site.
- Use your hosting account’s file manager or FTP client to upload the modified
- Test Your Website
- Open your website in a browser and verify that it automatically redirects to HTTPS.
Example .htaccess File with HTTPS Redirect
Here’s an example of a complete .htaccess file for WordPress with the HTTPS redirect rule added:
<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]
# END WordPress
</IfModule>
Tips for a Smooth Transition to HTTPS
- Backup Your Website
- Always back up your WordPress site, including the database and files, before making any changes.
- Check SSL Certificate Installation
- Ensure an SSL certificate is installed on your domain. Most hosting providers offer free SSL certificates via Let’s Encrypt.
- Update Internal Links
- Use a plugin like Better Search Replace to update internal links from
httptohttps.
- Use a plugin like Better Search Replace to update internal links from
- Test Your Changes
- Use online tools like Why No Padlock to identify mixed content issues and resolve them.
- Inform Search Engines
- Update your site’s URL in Google Search Console and other webmaster tools to reflect the new HTTPS URLs.
By following these steps, you can confidently migrate your WordPress website to HTTPS, improving security and providing a better experience for your visitors.