Force Redirect http to https

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?

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

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.

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

Maybe you should change your redirect directive to:

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

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]

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.

And this is the only code in the .htaccess file

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

1 Like

Just tried it and it breaks the site.

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

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

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

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)?

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.

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.

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.

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.

1 Like

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.

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.