Redirect http to https

HTTPS is a protocol for secure communication over a computer network which is widely used on the Internet. More and more website owners are migrating from HTTP to HTTPS, mainly due to the 5 following reasons:

  • Google announced that sites using HTTPS will get a slight ranking factor in Google search.
  • You can achieve faster performance with the new HTTP/2 protocol which requires HTTPS due to browser support. And yes, Charvi Associates supports HTTP/2 on all servers.
  • HTTPS is more secure and your visitor’s data is entirely encrypted.
  • HTTPS can build trust by enabling the green padlock in the visitor’s web browser address bar.
  • If someone is visiting a website from HTTPS and going to an HTTP website, the referral data is lost in Google Analytics. It usually ends up lumped together with the “direct traffic.” If someone goes from an HTTPS website to another HTTPS website, the referral data is still passed. So by migrating from HTTP to HTTPS, you can actually have more accurate referral data.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you have an existing .htaccess file:

Do not duplicate RewriteEngine On.
Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.