3 Way for redirect HTTP traffic to HTTPS in cPanel?

redirect HTTP traffic to HTTPS in cPanel
SSL Security

You can redirect HTTP traffic to HTTPS by editing the htaccess file in your cPanel hosting or WordPress site. The HTTPS or SSL (Secure Sockets Layer) connections are safe for browsing any websites on the internet.

In today’s lecture, you’ll learn what is HTTPS and how to automatically redirect a site’s HTTP to HTTPS. Let’s start with a brief discussion of HTTPS.

What is HTTPS?

The HTTPS means Hypertext Transfer Protocol Secure that is a widely used security protocol for creating an encrypted connection in online communications between web servers and browsers. All information transmitted between the web server and the browser is encrypted thanks to the use of SSL technology.

To establish an HTTPS connection, you need an SSL certificate. You must give all the information about your website and business identity when you want to enable SSL on your web server. Two cryptographic keys—a Personal Key and a Private Key—are then generated using that data.

You must enter codes into the .htaccess file to force your web traffic to use HTTPS. It’s helpful to review our .htaccess file before switching from HTTP to HTTPS connection. Because of, this file is typically hidden in cPanel. Skip to the redirection step if you already know about this.

Why You Should Redirect HTTP Traffic to HTTPS

The definitions of HTTP and HTTPS connections have been revealed by the discussion above. Now that we have set up this HTTPS connection on the website, let’s try to understand a little bit why.

When visiting a website, most of us fail to notice this. However, you should be aware of this as it is very important. The theft of your card information could result from any transaction on an unsecure or HTTP site.

As a result, whenever you access a website, make sure the connection is HTTPS. Today, almost all browsers display a red warning when visiting an HTTP site indicating that the site is unsafe. Your information may be leaked or stolen by hackers if you exchange any information with the site because the information exchange is not encrypted.

The main purpose of an HTTPS or SSL connection is data theft or fraud. which allows for the fully encrypted exchange of data between two servers. If you pay attention, you will notice that nearly all reputable company websites use SSL connections. Hope this gave you some ideas.

Note: Before making any changes that affect the live website, always create a backup of your website.

How to unhide .htaccess file in cpanel

Before anything else, let’s look at how to unhide the .htaccess file in the cPanel file manager:

▶ First, Login to cPanel.

▶ Select Files > File Manager > Document root from the menu.

▶ Choose the domain name you want to use now.

▶ “Show Hidden Files (dotfiles)” should be checked.

▶ Press the “Go” button.

▶ Open a new tab or window and after that, look for the .htaccess file.

▶ Click to the “Code Edit” from the shortcut menu when you right-click on the .htaccess file.

▶ A dialog box may appear for confirmation or verification; select “Edit” to continue.

▶ After the file has opened, enter your code here and change to the domain name with your domain name.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

▶ Then click “Save Changes” to complete the process.

▶ To ensure that your website is built correctly, test it. In that situation, it is preferable to clear the browser’s cache.

▶ In order to close the window, click “Close” at the end, if your SSL setting is active.

Redirect http to https using htaccess

1. Redirect http traffic to https (All Visitors)

If your .htaccess file already contains any existing code, add the following & instead of “yourdomain” enter your own domain name here. By using this code, you can redirect http traffic to https connection.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

2. Redirect a Domain to a Specific URL

Use the following example to redirect a domain to a specific URL. Then, replace the first example of “yourdomain” text with your primary domain and the second example of “yourdomain” text with the URL of the specific redirect destination.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

3. Redirect only a Specific Folder in Website

You can add the directive code shown below to redirect HTTP to HTTPS to a particular domain folder:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

Put your actual domain name in place of “yourdomain.” Additionally, substitute the actual name of the folder in the folder field for /folder. If you don’t want to use folders, then refer to our guide #2.

Last words:

I’m assuming you now understand, how to do a domain’s redirect http traffic to https using htaccess file. In addition, if you’re curious about SSL and the reasons why your domain requires an SSL connection. Then you can read our previous article what is SSL and the types of SSL certificates.

Please Don’t forget to bookmark our website and sign up for updates notification. Additionally, keep an eye out for new technology videos on our TechPoth YouTube channel.

Thanks for visiting!

Related Posts

This Post Has 2 Comments

Leave a Reply