Wiki / Encryption
Risk: HTTP → HTTPS redirect
The site also opens on http:// and the server does not move visitors to HTTPS, so form data and cookies can be read by anyone on the same network. Fix it today: it is one rule, but behind a proxy such as Cloudflare the rule is written differently.
What it does not mean. It does not mean the site has no HTTPS or no valid certificate. Only the answer to an http:// request is checked: any 3xx code with Location: https://… passes, while a 200 or a redirect to another http:// address is reported as a risk.
- In our report
- Risk (red), category weight 2.0 of 2.0
- Time to fix
- 10 minutes
- Can it break things
- Yes: a redirect loop behind a proxy, POST requests turning into GET
How to fix it
Redirect to the same host first (example.com → https://example.com) and to www only as a second step over HTTPS: the HSTS preload list requires it. The rules below keep the host name.
nginx (tested on 1.26.3)
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}On the test server http://example.com/path?a=1 went to https://example.com/path?a=1 and www.example.com to https://www.example.com/.
Apache, server config (tested on 2.4.59)
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>The Apache documentation calls this the preferred approach. Path and query string are kept. Each name (www) needs its own block, or a ServerAlias if one target is fine.
Apache, .htaccess (tested on 2.4.59)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]For hosting where you cannot edit the server config. Only correct when Apache itself terminates HTTPS: behind a proxy %{HTTPS} is always off and the rule redirects forever.
nginx behind a proxy (tested on 1.26.3)
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}Goes into the server block the proxy talks to. On the test server an HTTP request got one 301 and an HTTPS request got 200. Trust the header only if the server cannot be reached directly: otherwise anyone can send it.
Apache behind a proxy, .htaccess (tested on 2.4.59)
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]Cloudflare sends X-Forwarded-Proto with the value http or https, and CF-Visitor with {"scheme":"https"}.
Cloudflare
SSL/TLS → Edge Certificates → Always Use HTTPSFrom the Cloudflare documentation, not tested here. Available on every plan; the setting is hidden while the encryption mode is Off. Cloudflare advises against also redirecting at the origin once it is on. In Flexible mode an origin redirect to HTTPS causes a loop: switch to Full or Full (strict), or remove the origin rule.

X-Forwarded-Proto rule below. Test-server address flags are left out of the commands.How to check
curl -sI http://example.com/ | grep -iE "^HTTP|^location"Expected
HTTP/1.1 301 Moved Permanently
Location: https://example.com/Repeat with www. and with /path?a=1: path and query string must survive. To catch a loop run curl -sSL -o /dev/null https://example.com/: it prints nothing when all is well.
What can break
- When a proxy terminates HTTPS and talks to your server over HTTP, a rule that looks at the connection's own protocol redirects forever. On the test server curl stopped with
Maximum (50) redirects followed. - POST requests: after a 301, curl 8.5.0 with
-Lrepeated the request as GET and did not resend the data; with 308 it stayed POST. A client that does not follow redirects just receives the 301. Change webhook and API addresses tohttps://on the sender's side before you turn the redirect on. - Mixed content: the redirect does not change links inside your pages. Browsers block scripts, stylesheets and
iframeelements loaded fromhttp://addresses, and try to loadimgimages over HTTPS instead.

Possible values
The scan accepts any of these codes.
| Code | What it does | When to choose it |
|---|---|---|
301 | Permanent. The client may change POST to GET (RFC 9110, 15.4.2) | A normal website; the code our report suggests |
308 | Permanent, the method must not change (RFC 9110, 15.4.9) | Addresses that receive POST: APIs, webhooks |
302 | Temporary. POST may also become GET | Testing only |
307 | Temporary, the method is kept | Testing an address that receives POST |
Sources
- RFC 9110: HTTP Semantics, section 15.4 (301, 302, 307, 308)
- hstspreload.org: redirect on the same host requirement
- nginx documentation: return
- Apache documentation: Forcing HTTPS
- Cloudflare docs: Always Use HTTPS
- Cloudflare docs: causes of redirect loops
- Cloudflare docs: HTTP headers (X-Forwarded-Proto, CF-Visitor)
- MDN: Mixed content
Changes
- Page published; nginx and Apache rules, the loop behind a proxy and POST behaviour tested on a test server.
