Skip to content

.htaccess: how do I permanently redirect traffic to HTTPS?

Back to scripts and software

An htaccess is a file that can be placed in the root of the website. If you do not know how to create a .htaccess file you can use our help page: "What is a .htaccess file?".
The dot at the beginning of the file name is not a typo, this is necessary otherwise the file will not be picked up by the web server.

With this file it is possible, among other things, to redirect all website traffic from HTTP://exampledomainname.com to HTTPS://exampledomainname.com.

The code to be placed in the htaccess file is:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Back to scripts and software