How To Force HTTP Into HTTPS Using The .htaccess

How To Force HTTP Into HTTPS Using The .htaccess

In many bloggers today, there are some problem we should address this page, “How To Force HTTP Into HTTPS Using The .htaccess“. And this webmaster problem, this is a great solution. There are three categories to do this, “Redirect All Web Traffic From HTTP to HTTPS“, “Redirect Only Specified Domain“, and “Redirect Specified Folder“.
And now, let’s get ahead of the first topic;
How to Redirect All Traffic From HTTP to HTTPS?
If you want to force all traffic from HTTP to use HTTPS, you can simply insert the following code in the .htaccess file in your website’s root folder.
…………………………………………………………
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]
……………………………………………………………
REMINDER:
  • If you have already recent code in your “.htacess”, add this code above where there are previously rules with a similar preliminary prefix.
  • And be sure to change www.example.com with your real domain name.
***************************************
How to Redirect HTTP Only Specified Domain of HTTPS?
To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website’s root folder.
……………………………………………………………..
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]
………………………………………………………………

REMINDER:
  • If you have present code in your .htacess, add this that code above where there are previously rules with a similar initial prefix.
  • Just make it sure to change example\.com with the domain name you’re trying force to become https. Furthermore, you need to change www.example.com with your real domain name.
****************************************
How to Redirect Specified Folder?
If you want to force SSL on a exact folder you can attach the code below on a .htaccess file positioned in that exact folder:
……………………………………………………………….
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]
…………………………………………………………………
REMINDER:
  • If you have already a code in your .htacess, add this above code to where there are existing rules with a alike initial prefix.
  • Just make it sure that you modify the folder place to the real folder name. And also, be sure to change www.example.com/folder with your real domain name and the folder you want to modify the SSL on.
I hope it will help to everyone. If you have any concern regarding to our topic HTTP to HTTPS just leave a comment below.
= SHOW YOUR REACTION =

GOD BLESS US ! ! !
Comments area on How To Force HTTP Into HTTPS Using The .htaccess

Post a Comment

Previous Post Next Post

Contact Form