How to redirect website from HTTP to HTTPS using .htaccess

How to redirect website from HTTP to HTTPS using .htaccess

Chrome and Firefox showing the insecure warning on website without SSL certificate . Therefore, using an SSL-encrypted connection for safety of the website . It is very important to run website on HTTP to HTTPS.

Some time even SSL is activate on the website but it still showing in secure connection then we have to redirect it URL to HTTPS force fully

What is SSL?

Secure Sockets Layer (SSL) is a standard security technology for establishing an encrypted link between a server and a client in online communication

Editing .htaccess in cPanel File Manager

Note: Backup your website in case something goes wrong

  1. Login to cPanel
  2. Files > File Manager > Document Root for:
  3. Now select the domain name you want to access
  4. Check “Show Hidden Files (dotfiles)”
  5. Click “Go”
  6. After a new tab or window opens, look for the .htaccess file.
  7. Right click on the .htaccess file and click on “Code Edit” on the menu.
  8. Edit the file
  9. “Save Changes” when done
  10. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again.

Redirecting HTTP to HTTPS

1. Redirect All Web Traffic

If you have existing code in your .htaccess, add the following:

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

2. Redirect Only a Specific Domain

For redirecting a specific domain to use HTTPS, add the following:

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

Redirecting to HTTPS on a specific folder, add the following:

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

Note: Replace “yourdomain” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the actual folder name.

Tags: , , ,

1 thought on “How to redirect website from HTTP to HTTPS using .htaccess

Leave a Reply

Your email address will not be published.