http to https redirect

http to https redirection

Installed SSL certificate recently and now your website works both as https://abhatia.net and http://abhatia.net.

If you’re a WordPress user like me as many us or are you actively trying to increase your page’s rank in Google searches, Google announced that websites using HTTPS would get slight ranking factor boost in searches using their engine. Additionally, the newer HTTP/2 protocol has proven to have faster performance than the standard HTTP but requires HTTPS due to browser support.

Congratulations on securing your website. Now all you got to do is have http to https redirection done permanently so as all your website and content is transmitted securely. Google also ranks https website more then http website

Let’s get started. First Step  locate the .htacees website in root folder of your website. (its generally under /public_html/ folder)

To force all web traffic to HTTPS redirect, insert the following lines of code in the .htaccess file in your website’s root folder.

RewriteEngine On
RewriteCond %{HTTPS} !on RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Please NOTE: If there is  existing code in .htaccess, insert these above where there are already rules with a similar starting prefix.

Redirect Only Specified Domain

To force a specific domain to use  HTTPS redirection, insert the following lines of code in the .htaccess file

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} ^abhatia\.net [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.abhatia.net/$1 [R=301,L]

Make sure to replace abhatia\.net with the domain name where you want to http to https redirection. Additionally, you need to replace www.abhatia.net with your actual domain name.

Please NOTE: If there is  existing code in .htaccess, insert these above where there are already rules with a similar starting prefix.

Redirect Only Specified Folder

If you want to force https to https redirection  on a specific folder, insert the code below into a .htaccess file placed in that specific 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.abhatia.net/folder/$1 [R=301,L]

Please NOTE: If there is  existing code in .htaccess, insert these above where there are already rules with a similar starting prefix.

Make sure you change the folder reference to the actual folder name.  Then replace www.abhatia.net/folder with your actual domain name and folder you want to force http to https redirection

 
 
 
 
PS: IF you are getting connection is not secure due to mixed content, then checkout this blog