Monday, August 31, 2020

How to redirect Hostgator site requests for http to https

One of the things that bothers me every now and then is that when I create a new site and enter www.SiteName.com.au it goes to the http site instead of the https site and that may cause some features to fail, such as location features. Then my browser remembers the http site and I end up at the site that doesn't work property, having to re-enter the site using https. For me that's an inconvenience, but for uses of my site the real concern is they'll move on thinking the site doesn't work.

To fix this issue I need to automatically redirect people to the https address if they enter the http address.

Let's use an example.

Right now I find if I type www.JustLocal.com.au (one of my sites) I end up going to http://www.justlocal.com.au and the site comes up as not secure. The site still works, but a person seeing that message may not feel comfortable. So I want to redirect a user to use https.

If you have a site on Hostgator that does this, the following is what you can do to automatically redirect users.

Log into your cPanel
Select Files
Open the folder for the site - Previously the site was under the public_html folder, but more recently sites will be found in the folder you start at in Files.
Select the file .htaccess and click Edit (always a good a good idea of taking a copy of what is already there if something goes wrong you can paste it back. A photo using you mobile phone makes a quick image copy.)
Now paste in the following lines. I paste this at the start of the .htaccess file. The first line is usually blank so I enter this starting on the second line. I don't know if the blank line makes any difference.

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

Save the changes and Close

Now test to see if using http in the URL is automatically redirected to https. I did this edit as I wrote this post and it worked perfectly for me. I hope this post helps you solve this issue.

Kelvin Eldridge
www.OnlineConnections.com.au

PS. Performed the same change on the site www.CoronavirusVictoria.com.au and it worked perfectly. The .htaccess file did contain lines I'd not seen before so it's important not to touch any lines in the .htaccess file that are already there.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.