fix does not redirect HTTP traffic to HTTPS in wordpress website

WordPress – Fix “Does not redirect HTTP traffic to HTTPS”

You just passed your WordPress website to HTTPS with a brand new SSL certificate, but Lighthouse still warns you that you don’t redirect HTTP traffic to HTTPS ? Here is an easy way to fix this error.

You have to edit the .htaccess file, at the root of your FTP. This is the Apache server configuration file, to set up the behavior of the server. Most of the WordPress sites running on an Apache server have one, as WordPress generates it automatically at the install to set up the permalinks. If you don’t find it in the root folder, check if your FTP client is showing hidden files.

Edit the .htaccess file

First of all, duplicate your current .htaccess file on the server and rename it .htaccess-old to keep a backup. Then, open the .htaccess file with a regular code editor to edit it and force HTTPS redirection on your WordPress site.

In this file, you’ll find a snippet starting with # BEGIN WordPress and ending with # END WordPress. Don’t put anything inside this code or this will be overwritten as this code is dynamically generated by WordPress.

Right above that code, at the top of the file, paste this snippet :

What’s happening there ?

Let me try to explain this piece of code so you can understand what you are doing :

If the URL requested is not HTTPS

Rewrite the URL to HTTPS://yourdomain.com/yourrequestedURI and set a permanent 301 redirect

Then force the browser to update HTTP links to HTTPS to fix mixed content warnings (see Content Security Policy in the MDN).

And this is it ! Save your .htaccess file and update it on the FTP. Then refresh your website and check if everything is still working fine. Start a new Lighthouse audit to check if the HTTPS redirection is ok.

Don’t worry, in case of problem, if you get a 500 error on your WordPress website (internal server error), you just have to delete the modified .htaccess file and rename the .htaccess-old in .htaccess to restore your site to the initial state.

You can continue reading with the Flutter beginner tutorial here if you want to discover how to code native mobile apps with Flutter and Dart.

Thanks for reading !

Elya

Hi ! I'm a junior web developper and UX designer. Living in France, mother of 2, bookworm, cats lover, JS girl, yada yada yada. The usual stuff. Let's talk about code !

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

back to top