Force Redirect http to https

(Allen McFarlen) #1

I had a SSL certificate installed on my website yesterday and want to force all traffic to use https.

The server is a litespeed on a Cloud hosting account. I’ve spent hours on the phone with the hosting company with them finally saying that I would need to do scripting to get this to happen.

The suggest I use a .htaccess file which I have uploaded with the code suggested by “Whynopadlock”

That code is…

RewriteCond %{HTTP_HOST} [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

However as far as I can tell it is not forcing the https protocol. Tested on Safari, Chrome and Microsoft Edge.

Does anyone have a suggestion?

(NeilUK) #2

Try putting RewriteEngine On at the very top of your .htaccess file if it’s not there already.

(Allen McFarlen) #3

I did that and when I try to access the page I get the warning that the page can’t be opened. Possible reason is that a page is trying to redirect that is trying to redirect opening the original page.

(NeilUK) #4

Is there anything other than the redirect in the .htaccess file?

(Jannis from inStacks Software) #5

Maybe you should change your redirect directive to:

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

(Rob D) #6

I have this code in my htaccess file and it works for me:

# Force your entire website to go through https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R=301,L]

(Allen McFarlen) #7

I have tried all the suggestions above and in every case it breaks the site.

Same response of page calling to be redirected to the original page.

(Allen McFarlen) #8

And this is the only code in the .htaccess file

(Doug Bennett) #9

This one should work:

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

I tested this with your URL at

(Allen McFarlen) #10

Just tried it and it breaks the site.

(Doug Bennett) #11

What exactly are you getting when you try the .htaccess file?

(Allen McFarlen) #12

That’s an intereresting test site.

I’ve tried the original code and it passes on that site, and doesn’t break the site. Indicating that everything should work. And it doesn’t break anything. But testing on my windows browsers brings up the http page

(Allen McFarlen) #13

I have that code up there right now and it says that there are too many redirections. I’ll leave it in place for a bit if you’d like to have a look

(Doug Bennett) #14

I see the message, Not sure why it is happening.
Who is your hosting company?
Do you have anything else in the htaccess file?
Do you have any other redirects (maybe a cPanel entry)?

(Allen McFarlen) #15

The company is Netregistry in Australia. It’s a Cloud hosting package, not a cPanel one. No other redirects.

It’s the only thing in the .htaccess file.

I’ve swapped the code back to the orignial one at the top of the page as at least its not taking the site down.

(Doug Bennett) #16

I looked at their support area, and the code should work. I did notice your home page is getting errors on the browser console. Now that shouldn’t have any effect on the redirects.

ERR_TOO_MANY_REDIRECTS is likely due to an infinite redirect loop. Now since you have no other redirects, and the one I gave you works. I would go to your hosting support and either chat with them or cut a ticket.

(Allen McFarlen) #17

Thanks for the help. I’ll see what I can do with respect to contacting them and sorting it out. I was on the phone with them for hours yesterday for them to finally say that redirects were a scripting job and they weren’t responsible for that.

(Doug Bennett) #18

I can tell you for sure the script I listed above works 100%. It’s listed in multiple web hosting knowledge bases. It’s completely generic, notice no mention of your URL.

(Matthew Long) #19

It may well be a problem with your hosting company, in spite of what their support representative initially told you. Yesterday I noticed that my own site suddenly stopped working and was giving me a “Too many redirects error”, even though it had been working flawlessly for a few weeks (I’ve just made the move to SSL).

I contacted the hosting company and they initially told me that they fixed the problem. But then it only lasted 10 minutes before it happened again. This cycle kept being repeated for a couple of hours, with repeated assurances that they’d fixed the issue, until finally it was solved on their end. They never did tell me what the issue was, and why my site started spontaneously throwing up such errors.

(Allen McFarlen) #20

I’ve had the help of a fellow that does this stuff for a living, and every bit of code we’ve tried has either broken the site, or doesn’t do the job. He’s going to be calling Netregistry to find out what is happening on their end, and if they have a prefered method and syntax of redirect, as all the usual methods don’t work.