
How to redirect HTTP traffic to HTTPS using an .htaccess file
The below code when added to an .htaccess file will automatically redirect any traffic destined for http: to https:
1 2 3 |
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] |
This is generic code, no domain or page or subfolder needed in the htaccess code.
Redirect From Old Domain to New Domain *keeping* the query string:
1 2 3 |
RewriteEngine On RewriteCond %{HTTP_HOST} ^(?:www\.)oldDomain\.com$ [NC] RewriteRule ^ https://www.NewDomain.com%{REQUEST_URI} [L,R=301] |