Redirect all HTTP traffic to HTTPS
Updated 1 Dec 2026
What it means
Your site still answers on plain HTTP without redirecting to HTTPS, so some visitors browse unencrypted.
Why it matters
Logins and forms can be read or modified on public networks; search engines and browsers mark the site "Not secure".
How to fix it
- Add a permanent (301) redirect from http:// to https:// for every host.
- Then enable HSTS.
Configuration examples
nginx
server {
listen 80;
server_name YOUR_DOMAIN www.YOUR_DOMAIN;
return 301 https://$host$request_uri;
}
Apache
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
IIS (web.config (URL Rewrite))
<rule name="HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions><add input="{HTTPS}" pattern="off" /></conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Cloudflare
SSL/TLS -> Edge Certificates -> Always Use HTTPS: On
Node.js / Express
app.set('trust proxy', 1);
app.use((req, res, next) => (req.secure ? next() : res.redirect(301, `https://${req.headers.host}${req.url}`)));
Django (settings.py)
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
Laravel / PHP (AppServiceProvider::boot)
if (app()->environment('production')) { \Illuminate\Support\Facades\URL::forceScheme('https'); }
Any platform
301 redirect every http:// URL to the same https:// URL.
Check your fix
curl -sI http://YOUR_DOMAIN | grep -i -E "^HTTP|location"
References
- https://developer.mozilla.org/docs/Web/Security/Practical_implementation_guides/TLS