HTTPS is an extension of the Hypertext Transfer Protocol for secure communication over a computer network and is widely used on the Internet.
Redirect All Web Traffic
To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.
NOTE:Â If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32} \.txt(?:\ Comodo\ DCV)?$ RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Redirect Only Specified Domain
To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website’s root folder:
NOTE:Â If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Redirect Specified Folder
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:
NOTE:Â If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} folder RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R=301,L]
Great web site. Lots of useful information here. I’m sending it to some friends ans also sharing in delicious. And obviously, thanks for your effort!