.htaccess

How to redirect website HTTP to HTTPS using .htaccess

Note: Backup your website in case of something wrong.

Login into your cPanel
Use the file manager in cPanel to edit .htaccess file.
Now to put this code in the .htaccess file

RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

You can also redirect your website on the basis of port number

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

Change yourwebsite.com with your website domain. This code will redirect all requests received from port 80 to HTTPS.
If you are not able to find .htaccess in your hosting then click on the show hidden file.

Recommended Tutorials for you


Tags

Anuj kumar

This is Anuj Kumar. I’m a professional web developer with 5+ years of experience. I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials. .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button
Close
Close