Proper Method to redirect our visitors to HTTPS version via htaccess File


Proper Method to redirect our visitors to HTTPS version via htaccess File

HTTPS version

This tutorial we are going to see about redirect our visitors to HTTPS version via htaccess File.Most of them make Some small mistakes while HTTPS version redirection yes they use global SSL HTTPS version .htacess code It will affect the other website yesterday I face this problem I have SSl on my main website which contain’s user registration I use the global .htacess code(single code will enable HTTPS for all website which was hosted on our server we need a wild-card SSL for this) for redirect my website visitor’ to HTTPS version I have Single domain SSL only yesterday I migrate my one of website to my primary server at that time I face the SSL issue on the website I migrate from my another server nearly 2 hours I searching the solution for this issue after that I check My Main website htaccess file after that I refer some website about this issue finally I found the issue I use wrong code for HTTPS version I enable the HTTPS version for all my website that hosted on my primary server after adding the proper code My problem get fixed

Proper Method to redirect our visitors to HTTPS version via htaccess File

htaccess code for activate the https version for single domain

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

  • Replace the www.yourdomain.com to your actual domain name

htaccess code for non-www to www

 

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

  • Replace the example.com & www.example.com to your actual domain name

htaccess code for activating an SSL for Specific Folder (Example – Payment Gateway Link)

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

  • Replace the folder to your actual folder name
  • Replace www.example.com/folder to  your actual Domain URL  with folder directory name.

htaccess Method to Remove a .php and .html extensions

If you have Any Doubts in this topic please feel free to comment here I will help you



Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com