With this code, we will redirect all HTTP requests to HTTPS, which is very important for enhancing security and user trust.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
🔵 RewriteCond %{HTTPS} off:
This line checks whether the HTTPS protocol is inactive or not.
🔵 RewriteRule:
If HTTPS is inactive, this line will redirect all requests to the secure HTTPS version. R=301
also indicates a permanent redirect that will improve SEO.