Číst česky →

Redirecting HTTP to HTTPS - redirect 301 .htaccess

1 min read Hukot net WebHosting Apache

Do you have a valid active SSL certificate on your domain but still don't see the padlock icon in the URL bar? To display the green padlock icon correctly, you need to redirect traffic from HTTP to HTTPS. In a brief guide, we'll show you how to do that.

In the document root, locate the file .htaccess
The document root on Hukot hosting is located in the www directory, which means the path to the .htaccess file is www/.htaccess
If .htaccess is not present in the document root, create a new empty file.

We'll start by adding the activation of the redirection module to the file.

RewriteEngine On

Next, add the following:

RewriteCond %{HTTPS} off

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you want the traffic to always run on the www subdomain, add the following as well:

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Alternatively, if you don't want to have www in the URL bar, add the following:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]

RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Save the file and refresh the page.