This is a complete step by step guide to redirect http to https using .htaccess.

Having an HTTPS is critical now a days. It is a symbol of trust. Google Chrome, Firefox, and other popular browser display a warning when a visitor load a website running on HTTP. They mark them as unsecure site. 

For an eCommerce store, it is much more vital to load the site on secure socket.

In this guide, you will learn a simple and easy to follow procedure of forcing a redirect HTTP to HTTPS by using .htaccess.

Redirect HTTP to HTTPS using .htaccess

Edit .htaccess file using FTP or cPanel

Editing .htaccess in cPanel File Manager

How to edit .htaccess file in cPanel File Manager:

  1. Open your cPanel account
  2. Click on File Manager from the Files Tab
  3. Find the “Setting” at the top right corner of the page, click on it
  4. Click on the Document Root for (the domain name) and check the Show Hidden Files (image below)
  5. Save to update the File Manager
  6. Find the public_html file and click on it
  7. On the next page, you will find the .htaccess file
  8. Click once on the .htachess file and then click on the “Edit” at the top bar
  9. A warning box will pop up, but click on Edit
  10. On the next page, a code editor will open
  11. Edit the code
  12. Save the file

After everything is done, check the site if the changes are made. If anything goes wrong, follow the same procedure to find the .htaccess file and restore the older version.

Now, you know how to edit the .htaccess file, let’s redirect HTTP to HTTPS using the edit .htaccess file method.

Redirect HTTP to HTTPS in Apache

1. Redirect All Web Traffic

Add this code below the existing code in your .htaccess file.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

 

2. Redirect Only a Specific Domain

Add this code to redirect a specific domain to use HTTPS.

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomain\\.com [NC] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

 

3. Redirect Only a Specific Folder

Add this code to redirect a particular folder to use HTTPS.

Services we offer:RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder 
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

 

Note: At the place of “yourdomain” in the code, add your domain name. Similarly, replace the /folder with your folder name.

 

HTTP to HTTPS redirect in NGINX

  1. Login to NGINX webserver
  2. Add return 301 https://$server_name$request_uri in server directive.
  3. Save the file.
  4. The last step is to restart your NGINX web server.

Note: Take a backup of nginx.conf or default.conf file

HTTP redirect to HTTPS in Cloudflare

If you are using Cloudflare, then you can perform HTTP redirection easily.

  • Login to Cloudflare
  • Selection your website
  • Go to Crypto tab
  • Scroll down to “Always Use HTTPS section”
  • Make sure it is turned ON

Having an SSL certificate on your site, and loading it over the HTTPS is a necessity if you are running an online business.

Esta resposta foi útil? 0 Utilizadores acharam útil (0 Votos)

Powered by WHMCompleteSolution