To redirect a website from HTTP to HTTPS, you can use the following code in .htaccess file
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
If you want to redirect HTTP to HTTPS and keep SSL verification pages on HTTP, this is needed on Cpanel servers.
RewriteEngine on RewriteCond %{HTTPS} !=on [NC] RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/ RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
If you wish to add redirect in Apache VirtualHost, use the following VirtualHost entry.
ServerName www.yourdomain.com Redirect permanent / https://www.yourdomain.com/
See htaccess
Leave a Reply