How to set a website default open with https using htaccess
Hi guys, in this post I'm share with you that how can we set default website open with https.
so lets start..
Many times, it is beneficial or even necessary to make sure your website's visitors are accessing your site using an SSL-encrypted connection, whether for security, accessibility, or PCI compliance reasons. If you’re not familiar with SSL and would like to know more, please review our article What is SSL and why is it important? for more information.
In most of hosting includes a free SSL Certificate by default for all Business Class Hosting Plans. This SSL can be activated with a simple switch in your Account Management Panel (AMP) under My Account > Manage Free SSL.
Forcing visitors to use SSL can be accomplished through your .htaccess file using mod_rewrite. If you’d like more information on mod_rewrite please read our article.
To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.
Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Be sure to replace www.example.com with your actual domain name.
To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:
RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} folder RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]
Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folderwith your actual domain name and folder you want to force the SSL on.
No comments