How to force all traffic to HTTPS

Hi,

I followed the directions to redirect HTTP requests to HTTPS that are described in the article called: “How to force all traffic to HTTPS

When I copy the file “.htaccess” into the htdocs directory and then try to access the website I get the below error:

500 Error, please check your php script / enable display_errors in your cpanel

If I delete the file the error goes away, so I know that it has something to do with the file.

The contents of the file are as follows:

##################################################

#

# DO NOT EDIT THIS FILE DIRECTLY

#

# Create a new .htaccess file in your htdocs

# directory (or example.com/htdocs/ directory)

# to add your own rules or override these rules.

#

##################################################

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

DirectoryIndex index.php index.html index.htm index2.html

Did you read what file says?

##################################################

#

DO NOT EDIT THIS FILE DIRECTLY

#

# Create a new .htaccess file in your htdocs

# directory (or example.com/htdocs/ directory)

# to add your own rules or override these rules.

#

##################################################

Yes, I didn’t edit it directly. I downloaded the file and edited it in a text editor.

Same thing. You need to follow the instructions from the second half of the file. Admin, maybe you want to change that text to remove the word “Directly”. It might make it clearer.

Create a new .htaccess file in your htdocs
directory (or example.com/htdocs/ directory)
to add your own rules or override these rules.

That text is not under Admin’s control. All ifastnet resellers have this permanently set by iFastNet themselves and can not be changed

I’m not sure what I’m missing on this?
Does someone have an example of what should be in the “.htaccess” file that gets uploaded to the “htdocs” folder? I’ve also already tried downloading the original “.htaccess” file, deleting all of the content in it and then adding the redirect code to it and uploading this new file to the “htdocs” folder with the same results. It would probably be a good idea if there was a sample file that worked that could just be download and re-uploaded to anyone’s “htdocs” folder to accomplish this HTTP to HTTPS redirect.

Thats the correct procedure. Did you remember to clear your cache?

Yes, clearing the cache didn’t make any difference.

Can you share the URL?

If you installed the SSL cert just a few mins ago, it may take time. Or it may the error: Error_Ssl_Protocol or something like that.

It’s been several days since setting up the SSL Cert, so I don’t think that is it. I did find a less elegant work around, and I’m not sure what the negative ramifications are as far as Search Engine Optimization (SEO) as well as any possible “unsecure” warning messages a web browser may throw onto the screen to a user before it tries to switch to a secure screen. I added the below java code I located online, to the top of the index.html page I’m using, which will force the page to reload as HTTPS. So far it seems to have worked in the four web browsers I’ve tried.

Save an .htaccess file in your htdocs directory. Make sure it is saved exactly like that (with the . infront)
The rules are

#####################Redirect all http -> https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
1 Like

U should add the below code in .htaccess file

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

The .htaccess file should be in htdocs folder if not please create !

*not root folder

The .htaccess code works just fine here. Can you screenshot your .htaccess file and it’s location? Sharing your domain might also help.

@ _recce
For some reason the code the _recce gave me worked! I’m not sure why that code worked, but the other ones I tried didn’t, but I’m glad it did.
Thank you for everyone’s help!!!
Have a great day!

2 Likes

I just edited it, the word doesn’t really add anything.

No, it is my text, I wrote it for InfinityFree. The default .htaccess content can be customized for every domain name. Any other reseller using this exact template stole my property.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.