How can we force the domain to serve securely using HTTPS with an .htaccess file?

 


Once SSL certificate has been added to the domain, all visitors to the site can be forced to use HTTPS to ensure the website traffic is secure. Below code can be used in .htaccess file:

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

 


Related #tags:     #.htaccess     #apache    

Related questions




Looking for change? Click below to prepare for technical interview.


Technical Interview Questions