Redirect HTTP to HTTPS

How to redirect HTTP traffic to HTTPS using an .htaccess and NGINX configuration

April 16, 2018
In category Makeitwork

The below code when added to an .htaccess file will automatically redirect any traffic destined for http: to https:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

For NGINX, the following configuration can be used inside a server block:

if ($scheme != "https") {
    rewrite ^ https://$host$uri permanent;
}
0 0

comments powered by Disqus