Creating HTTP to HTTPS re-direct [2024] 💥
There are many different options for linking http to https depending on the situation of your website. For example, if you use a CDN network, you don't actually have to do anything on your website or your own hosting. Furthermore, this re-direct can be performed by Apache, Nginx, Cpanel and quite a few third parties that could arrange your hosting situation for you. Let's start with the easiest one: C-panel.
Advertisement
1. Cpanel
If you plan to use a CDN network in the future, it's okay to leave these settings as they are. For the time being, we assume that you are not using a CDN.
To start with, there are already two different options for Cpanel. I'll start with my favorite way which is to create a direct redirect and then login to your public_html and edit the .htaccess file there.
a. Create redirect
Log in to your Cpanel by going to yourdomainname+tld/cpanel. Search through the search bar for the chapter "Redirects". It pretty much speaks for itself once you get there, Cpanel is a perfect and easy to understand hosting environment but just to be clear, check out the screenshot below.
b. edit .Htaccess
To begin with, in your Cpanel file manager settings, make sure to display your hidden files as shown below.
Find your .htaccess file and right click it, choose "edit". See screenshot below.
Paste the following code in your .htaccess file somewhere at the bottom. The location doesn't matter much, but the bottom is the easiest.
# http 2 https redirect
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
The result should look something like this. There are also other hosting panels that can do the same for you, such as Pleskpanel, but unfortunately I can't give screenshots of everything. Cpanel is the most used and the best.
2. FTP
If you have to do this with FTP because you don't have a hosting panel that can do it, then it's time to order a better hosting. I'll explain it below as well. To get started, download Filezilla, the best free FTP Client. Use ftp.yourdomainname.tld as user and the password your hoster gave you for FTP, port is 21. This doesn't always work because some hosters have special "security settings", in which case you should contact them to find out which ones data you can log in. Sometimes filling in your server IP works for user.
To start, we're going to show the hidden files again.
Logged in you should automatically be in the public_html folder on the right side of the screen (server). You will see the .htaccess file here, right click > edit. Follow the instructions in Cpanel above, they are exactly the same and there is also the code that you paste into the file at the bottom.
3. Other methods
Listen, the 2 options above are suitable for beginners, other methods definitely not like changing httpd.conf in Apache, or Nginx which is installed on few servers. Someone who orders Nginx on his server is not a beginner and I don't have to explain anything to them. Furthermore, it may be that you are with special hosters such as Kinsta, WP-Engine, Sucuri, etcetera. If so, search their website for a tutorial for this, or search directly in Google, for example, for "http to https Kinsta". All these companies offer their own tutorials for this.
4. Cloudflare
Cloudflare is a CDN that stores your website on many servers around the world. If you use a CDN you have adjusted the namer servers at the registrar for your domain, which means that Cloudflare now takes over some tasks from your own server such as SSL certificate but also this re-direct although it should work if you are on your server set this up as described above. If not (try that first) follow the directions below to set up the re-direct directly with Cloudflare. Cloudflare is free but there are many more CDN providers, if you're elsewhere I suggest you check their site again for a tutorial adapted to that CDN.
Setting up with Cloudflare is extremely easy. Log in to Cloudflare and choose the correct website if you have more than one. Go to the SSL/TLS > Edge Certificates tab. The screenshot below shows what you're doing there.
Advertisement