Htaccess Redirect To HTTPS – How to Redirect Your Web Traffic to HTTPS?

Htaccess Redirect To HTTPS – How to Redirect Your Web Traffic to HTTPS?

Google has started showing insecure warnings on sites without SSL certificates. Without SSL, your site will show unsafe to your visitors. Therefore, it is now essential to have an SSL certificate on your site.

What is SSL?

SSL is a short-term of Secure Socket Layer which helps in establishing an encrypted bond between a web-server and a web browser.

This bond ensures that all data transferred between the web-server and web browsers remain secure and private. SSL certificates are essential for making the trust of your customers. SSL certificate encrypts the sensitive information of your visitors.

When do you need to worry about SSL?

1. Is your Website includes contact forms, login panels, search options, etc.?

2. Is your Site without SSL or HTTPS://?

If  YES to the above questions, you need an SSL certificate for your website right now. If you don’t purchase the SSL certificate, There is a warning message Not Secure in the Address bar which will display to the visitors on visiting your site. SSL certificates are essential for making the trust of your customers.

Editing the Htaccess File

To redirect your web traffic to the HTTPS, you need to edit the code in the htaccess file. If you are a beginner in WordPress and don’t know about updating the htaccess file, I’ll tell you how you can edit the htaccess file. If you know the ways of edit the htaccess file, you can skip this.

Ways of Editing the htaccess File

1. You can edit the file on your computer and then upload the file using FTP.

2. Edit the files using FTP details of your site remotely.

3. Using File Manager in cPanel.

4. Use Text Editor and SSH to edit the file.

Editing .htaccess in cPanel

1. Login cPanel.

2. Click on File Manager icon.

3. On the upper right-side click on Settings.

Htaccess Redirect To HTTPS – How to Redirect Your Web Traffic to HTTPS? 1

 4. Check Show Hidden Files to display the .files(dotfiles).

Htaccess Redirect To HTTPS – How to Redirect Your Web Traffic to HTTPS? 2

5. Locate the .htaccess file.

6. Right-Click on the htaccess file and select Edit from the menu.

7. Edit the file.

8. After that Click on Save Changes.

1. Redirect All Web Traffic

If your htaccess file already has the existing code, then add the following code:

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

2. Redirect Only a Specified Domain

Redirecting only a specific domain, add the following code:

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

3. Redirect only a Specified Folder

Redirecting a specific to the HTTPS, add the following code:

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

Before saving the file, make sure to replace yoursite.com with your domain name.

Scroll to Top