How to Redirect HTTP to HTTPS in WordPress Without Breaking Your Website

Redirecting HTTP to HTTPS ensures that visitors access your WordPress website through an encrypted connection. A proper migration requires an SSL/TLS certificate, permanent redirects, updated internal URLs and checks for mixed content.

Georgios Angelis
By
Georgios Angelis
Georgios Angelis
Web Developer - IT Specialist & Digital Marketing Expert
Georgios Angelis is a Web Developer and Digital Marketing Expert based in Thessaloniki, Greece, with extensive professional experience in website development, search engine optimization (SEO), digital...
- Web Developer - IT Specialist & Digital Marketing Expert
5 Min Read

Whilst an SSL certificate is installed, your site will continue to be available on both HTTP and HTTPS. This can therefore lead to duplicate pages and also raise security issues.

Correctly setting up a redirect ensures that users are sent to HTTPS and encourages search engines to ‘vote’ for the secure site version.

Install and Confirm SSL Certificate

Confirm that your hosting has a suitable SSL or TLS certificate. Many hostings provide free certificates (via Let’s Encrypt) and these can be installed using cPanel or Plesk.

Manually browse to your sites HTTPS version and confirm it displays and that there are no certificate related errors.

Do not set up a redirect to HTTPS until you are confident that HTTPS is functioning.

WordPress Settings

Go to WordPress Dashboard > Settings > General.

Find the:

WordPress Address (URL)

Site Address (URL)

Change these from http://example.com to https://example.com. Ensure that any sub-folders are still included.

Click Save. You may then need to log back into WordPress.

This alters the URLs associated with WordPress but will not automatically transform all HTTP database URLs to HTTPS.

Option 1 – Redirect HTTP to HTTPS using .htaccess

If your hosting is based upon Apache and allows .htaccess files, you can edit these using FileZilla or your hosting’s file editing tool.

Within your WordPress folder, find and copy the .htaccess file.

Above the current # BEGIN WordPress line, add:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

Ensure that example.com is replaced with your domain name.

This produces a 301 redirect and retains the original URL including any sub-folders and query strings.

Further server-side settings may need to be altered if your site is behind a reverse proxy or CDN.

Option 2 – Set Up HTTPS Redirection within Nginx

Unlike Apache, Nginx does not recognise .htaccess files. HTTPS redirection has to be set up server-side.

Edit or add an HTTP server block so that it includes:

server {
    listen 80;
    server_name example.com www.example.com;

    return 301 https://example.com$request_uri;
}

Check that the new settings are correct and then re-start Nginx:

nginx -t

If this is successful, run:

systemctl reload nginx

Correct user rights are required to run these commands.

If your server is managed via Plesk, cPanel or another hosting management system, then utilise the HTTPS redirect feature within this instead of directly editing server-side configuration files.

Option 3 – Force HTTPS with a WordPress Plugin

Those who do not have server-side editing rights can install a plugin such as Really Simple Security.

Install and activate the plugin and then follow its guidance for setting up SSL.

Whilst this option is easier to manage, server-side redirection is typically better as it can redirect users prior to WordPress and PHP being engaged.

Never set up more than one separate redirect system as this can result in an infinite redirect loop.

Alter WordPress Database URLs

Post-HTTPS activation, previous content such as images, posts and CSS may continue to use HTTP URLs.

This can trigger mixed content alerts and even result in browsers preventing access to some of these items.

If you can use WP-CLI, first back up your database and then test a find and replace function:

wp search-replace \
'http://example.com' \
'https://example.com' \
--skip-columns=guid --dry-run

Assess the test output. If this is satisfactory then run:

wp search-replace \
'http://example.com' \
'https://example.com' \
--skip-columns=guid

WP-CLI is able to correctly edit WordPress specific database data, in contrast to basic SQL find and replace functions which can adversely affect data.

The Better Search Replace plugin can also be used for this purpose.

Test Redirects and Optimise SEO

Enter the following command to analyse your server’s reply:

curl -I http://example.com/sample-page/

Ideally, if a 301 redirect is working then the server will respond with something akin to:

HTTP/1.1 301 Moved Permanently
Location: https://example.com/sample-page/

Subsequently, refresh both your WordPress and CDN caches. Investigate canonical URLs, and upload your HTTPS sitemap to Google Search Console.

Furthermore, inspect your browser’s developer console to check for mixed content issues.

Ideally, each HTTP page should be instantly redirected to its HTTPS counterpart. Ideally there should be no intermediary redirects and no inaccessible items.

Share This Article
Georgios Angelis
Web Developer - IT Specialist & Digital Marketing Expert
Follow:
Georgios Angelis is a Web Developer and Digital Marketing Expert based in Thessaloniki, Greece, with extensive professional experience in website development, search engine optimization (SEO), digital advertising, e-commerce, and web technologies. He is a Google-certified professional and runs Netclick Digital, a digital marketing agency recognized as a Google Partner. His professional expertise includes Google Ads, Meta Ads, technical SEO, WordPress development, PHP programming, web analytics, marketing automation, and digital growth strategies. Combining technical development skills with data-driven marketing expertise, he helps businesses improve their online visibility, website performance, customer acquisition, and digital presence. As a contributing author at SkillOnPage, Georgios shares practical knowledge and professional insights on web development, programming, digital marketing, SEO, artificial intelligence, e-commerce, and emerging digital technologies.
Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *