1. Home
  2. SSL – Redirect HTTP to HTTPS with the .htaccess

SSL – Redirect HTTP to HTTPS with the .htaccess

SSL certificates

Before redirecting to HTTPS, make sure you have an SSL certificate on your domain.

You can check this by visiting your website with https: // at the beginning of the URL. For example, for planethoster.com, type https://planethoster.com to check.

In case of error, you will have an error of the type “Your connection is not private”.

In the majority of cases, you will not get an error message because PlanetHoster installs free SSL certificates on all accommodations.

HTTP to HTTPS redirection

Following the installation of the SSL / TLS certificate, the traffic will not necessarily be redirected to HTTPS.

If you use a CMS Ex: WordPress, PrestaShop or Joomla !, you can create this redirection by following the tutorials below:

Following the configuration of your CMS or for homemade sites, you will need to edit or create a .htaccess file at the root of your site.

For simple traffic redirection, add the following code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Warning: If you have several additional domains in your public_html, the redirection will be problematic, it will redirect all the traffic in HTTPS. (Even for domains without certificate)!

This code will allow you to redirect while specifying the domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^YourDomain\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

Your website doesn’t have a green lock?

When your site is in HTTPS, on some occasions it may happen that some of your web pages remain with items that are not secure.

Result: The site in question does not show the appropriate sign is the green padlock stating that a site is completely secure in HTTPS.

To remedy this, we invite you to visit the following link to determine the elements causing this problem: https://ssl-lookup.io/

By entering your website link, the tool will automatically list all unsecured items on your site.

It will then be necessary to examine the results and make the change on your site in order to solve the situation.

Updated on 6 October 2021

Was this article helpful?