Forcing https throws error

Whenever I am trying to use the htaccess to redirect http to https with the following code:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I am being thrown a 500 error.
The error is 500 Error, please check your php script / enable display_errors in your cpanel.

What can be done about it?

Try to use this code instead and see if that throws an error:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} http
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC]

Did you try to enable display_errors in your control panel, like the message suggested?

1 Like

Yes I tried…but somehow no error shows up.

Yes it still throws error.

Then what is your full .htaccess file code, so I can continue to help you?

1 Like

I have pasted the only part that I have in my .htaccess file. :frowning:

@Admin @Ergastolator1
I tried the following:

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

Using the above the error goes away, but automatic redirection doesn’t happen. I need to manually enter https to go to the secured site or else it opens me the unsecured version.

@Admin @Ergastolator1 Any ideas on what can be done about it?

Hi there,

you can alternatively try using the Cloudflare integration and activating the force HTTPS setting there.

2 Likes

@Magnus Using cloudflare would be a good option as AFAIK it allows SSL on subdomains too but the drawback would be of a shared SSL. So I was looking for an option to enforce SSL on the main domain and subdomains. But since SSL on subdomains is not available on subdomains on infinityfree, hence I was looking to use Letsencrypt SSL and force redirect to https for the main domain using htaccess.

I do understand that. Normally, you should be able to add the rule to the .htaccess file, but I don‘t know what is going wrong with your implementation of it.

1 Like

@Magnus I too am confused, is there any way or files that you would like me to share for you to take a look into?

The code:

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

Should be working fine; it isn‘t though. I don‘t really know why.

@Magnus For me only on one device it is being served. Other devices both http and https are being served when requested manually. And is clouflare ssl available for subdomains?

It has https; BUT ONLY if I manually enter https://.

THIS MEANS —> You will need to force HTTPS if you want all your visitors to automatically be redirected to the HTTPS version of your site. :slight_smile:

1 Like

@Magnus Exactly, and it’s happening inspite of me having the .htaccess file with the above code. It would be great to receive some solution from someone, even from @Admin. :slight_smile:

I just copy pasted the .htaccess snippet from our knowledge base onto your website and it appears to be working perfectly now.

I didn’t find any other .htaccess files in your account by the way.

1 Like

@Admin I had removed the .htaccess as it wasn’t working and then I moved on to try cloudflare. The site is currently redirecting to https but am not sure whether its the cloudflare or letsencrypt.

In the screenshot, you can see multiple references to Cloudflare. So it’s quite clear that you’re connecting through Cloudflare with Cloudflare’s certificate.

1 Like