Guides

Redirecting from HTTP to HTTPS

htaccess script example

Once an SSL certificate has been installed, it is possible to redirect requests received by the web server via the HTTP protocol to the secure HTTPS protocol.

The redirect is carried out by modifying the hidden .htaccess file located in the root folder of the website (to see it, it may be necessary to display the hidden file): it is a simple text file without an extension, so a text editor (notepad, gedit, notepad, etc.) is enough to modify it.

The directives to be included in the .htaccess file are as follows:

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

IMPORTANT

  • In the case of a newly created .htaccess file, make sure you save it without the extension.
  • If the .htaccess file already exists, the instruction "RewriteEngine On" will already be present in it, so only the last two lines need to be inserted, making sure they are in the right place, depending on the existing instructions.

After the change, check that the redirection works correctly by browsing the website.