To redirect HTTP traffic to HTTPS you can add below lines to either .htaccess file or in apache .conf file.
Table of Contents
“Although it is recommended that for website universal configuration you must use .conf file rather than .htaccess. Because we only use .htaccess file when we want to make a specific folder/link changes in our website.”
=> Configuration i am using in my apache virtualServer .conf file :-
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com(OR subdomain.example.com)
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
1. Redirect All Web Traffic :-
To redirect all HTTP traffic to HTTPS:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
2. Redirect Only a Specific Domain :-
For redirecting a specific domain to use HTTPS, add the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
3. Redirect Only a Specific Folder :-
Redirecting to HTTPS on a specific folder, add the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://example.com/folder/$1 [R,L]