How to translate a site to https, redirect from http to https and from www to non-www
Today, sites without encryption of the connection are generally recognized as insecure, so there is a need to transfer them to a secure connection. In addition to protecting data, a secure connection is required to implement various functions that are not available through the usual protocol.
How to translate a site to https
To translate a site, you first need a working SSL certificate, for example, you can use the free SSL Let's Encrypt. You can order and install a certificate manually, but the easiest way to do this is through the hosting control panel. When the certificate is ready, you need to redirect from http to https all requests on the site. Also, along with this, you often have to configure other redirects - you can configure a redirect from www to non-www .
Redirections can be done in different ways - you can enable this option in the hosting site settings or write redirection rules in the .htaccess file, which is stored in the site root. If such a file is not there, you can always create it yourself. First of all, you need to enable the server redirection functionality, for this, if the following entry is not in the file, it is important to add it:
RewriteEngine On
Then you can write any redirection rules. Examples of such rules will be given below.
Redirects from http to https
Directly for redirecting from http to https, you can try to write different rules, since different sites may need different options. Using the selection method, you can choose the right one until a working rule is found. Rule example:
RewriteCond% {HTTPS}! = on
RewriteRule ^ (. *) $ Https: //% {HTTP_HOST} / $ 1 [R = 301, L]
Redirect www to non-www
As mentioned above, along with the redirect from http to https, you will most likely need to redirect from www to non-www. This is done in the same way as redirecting from http to https - either through the option on the hosting, or through the .htaccess file. It must contain the following:
RewriteCond% {HTTP_HOST} ^ www \. (. +) $ [NC]
RewriteRule ^ http% {ENV: protossl}: //% 1% {REQUEST_URI} [L, R = 301]
Website adaptation for https
After completing the above steps, you need to check the site and adapt it to the new settings. Namely, change the addresses in robots.txt , in the sitemap sitemap.xml etc., correct the addresses in links and resources so that all content is loaded via https. Otherwise, when entering the site, the browser will display a notification next to the address bar - connection is not fully protected and there will be an error icon. In this case, the console will contain entries with phrases - mixed content , highlighted in red and yellow. The addresses highlighted in red are blocked, yellow are just warnings.
It is important not to forget that a site on https is a new site for search engines, you will need to add a new version of the site everywhere - in all services, webmasters, etc. Thus, in order to translate the site to https , you will need to perform a few simple steps. Namely, to do redirect from http to https and adapt the site itself - change all links on it for the new protocol.
Latest articles
- 03.04.24IT / Уроки PHP Уроки простыми словами. Урок 3. Все операторы PHP с примерами, с выводом работы кода на экран.
- 02.04.24IT / Уроки PHP Уроки простыми словами. Урок 2. Типы данных в PHP с примерами.
- 02.04.24IT / Уроки PHP Уроки простыми словами. Урок 1. Коротко о языке веб-программирования PHP. Основы синтаксиса.
- 09.11.23IT / Database Errors when migrating from MySQL 5.6 to 5.7 and how to fix them - database dump import failed with an error or INSERT does not work. Disabling STRICT_TRANS_TABLES strict mode or using IGNORE
- 08.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes