Redirect HTTP to HTTPS
Send every plain-HTTP request to HTTPS with a permanent (301) redirect. Replace example.com with your domain.
NGINX, in the site's config:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}Apache, in .htaccess (mod_rewrite enabled):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Notes
- Use 301 for permanent moves
- Install the SSL certificate first
- Check that the redirect does not loop
