28. 9. 2022

Web redirection from HTTP to HTTPS

If your website runs on the secure HTTPS protocol, which should be a matter of course, you must not forget to set the redirection from insecure http: // to https: //.

There are several reasons to do this. The first, and probably the most important, is to ensure the privacy of our visitors when browsing the websites that the secure HTTPS protocol brings. The second reason may be, for example, to avoid duplicating URLs. This can be a problem, for example, with search engines such as Google, List, etc., which can penalize your website for the same content being available at two different URLs, resulting in a reduction in search results.

Redirect to HTTPS using .htaccess

The easiest and most common way to do this is to set all URL redirects to https to the correct settings in the .htaccess file.

You may often come across the following solution, which may work perfectly well in most cases.

Plain Text
.htaccess

But you’ll run into some servers. Specifically, there will be a problem, for example, with the Czech web hosting Wedos, which does not redirect you as you imagine. Due to the way the directory structure is created on this hosting and the default .httacces file is set, it will be redirected to a URL of the type https://www.pavelkovar.cz/domains/pavelkovar.cz/ – which we really don’t want to.

The following redirect method on Wedos hosting is already working without a problem, due to the absence of% {REQUEST_URI}, which currently contains the entire directory path to your site.

Plain Text
.htaccess

However, in order not to make it so simple, we will come across previous solutions with Active24 hosting, where they will not work for you, and in the official help (https://faq.active24.com/cz/098327-htaccess-editace-specifika#HTTPShtacces) they recommend completely different At first glance, a more complicated solution.

Plain Text
.htaccess

Finally, it is also worth mentioning that in order to achieve the correct redirection, it is important to redirect the status with the code 301, which indicates a permanent redirection of the given URL.

Redirect to www

Sometimes it can also be useful to have a redirect to www in addition to redirecting to https. Therefore, if the user enters the address neco.cz, he will be redirected to www.neco.cz. This mainly helps to duplicate the URL (so that your site doesn’t run on multiple domains).

Plain Text
.htaccess

Using HTTPS in WordPress

If you’re running a WordPress site, in addition to setting up redirects with .htaccess, you’ll need to make a few minor tweaks. I’m setting up WordPress settings in this article .

Automatic translation

This is an automatic translation of the original article in Czech.


Share

Leave a Reply

Your email address will not be published.