HTTP to HTTPS Redirect: Setup & Best Practices
How to redirect HTTP to HTTPS correctly: Nginx, Apache, Cloudflare, HSTS headers, and avoiding redirect loops.
Nginx
server {\n listen 80;\n server_name example.com;\n return 301 https://$server_name$request_uri;\n}Apache
RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]HSTS Header
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Try It Free
Use our free online tool — 100% client-side, no data leaves your browser.
Open SSL Checker