How to Redirect HTTP to HTTPS Without Losing Paths or Queries

Verify TLS first, then test HTTP-to-HTTPS redirects for apex and www, parameterized URLs and requests whose methods must survive the redirect.

FBFenwei BianAuthorNov 24, 2026
  • https
  • redirects
  • web-hosting
  • guide

To move a site from HTTP to HTTPS, make HTTPS work on every hostname you will serve, then configure the HTTP listener to send each old URL to the intended HTTPS URL. Test the status and the exact destination. A working homepage does not establish that a bookmarked path, query or form still works.

Prove the destination is ready first

Visit the HTTPS version of the apex and www names directly. Each hostname that receives an HTTPS request needs a working TLS endpoint, even when its only job is redirecting to the other hostname. The certificate exchange takes place before the client can see the HTTP redirect.

Check the production certificate name and chain and confirm that a few real paths render normally. In a staging setup, also check for scripts, styles or images that still point at an insecure URL. Once the HTTPS endpoint is ready, configure the redirect at your host, load balancer or web server. DNS sends traffic to the right service; it does not set an HTTP redirect status.

Pick the status for the request you support

HTTP semantics distinguish temporary 307 from permanent 308. Both preserve the method when the client follows the redirect automatically. A client following 301 or 302 may change a POST to GET. For a permanently moved public page, Google treats both 301 and 308 as permanent redirects. For a form or API, update documented endpoints and clients to send directly to HTTPS. A redirect cannot retroactively protect sensitive data a client already sent over HTTP.

Check the path, query and final response

Suppose the intended site is https://example.com and both HTTP hostnames must land there. Use a request such as curl -sS -o /dev/null -D - 'http://www.example.com/docs/start?lang=en&source=guide'. Inspect the first status and the Location header without automatic following. Then check the final response separately with curl -sS -L -o /dev/null -w '%{url_effective} %{http_code}\n' 'http://www.example.com/docs/start?lang=en&source=guide'.

InputExpected first destination
http://example.com/https://example.com/
http://www.example.com/docs/start?lang=en&source=guidehttps://example.com/docs/start?lang=en&source=guide
http://example.com/images/a%20b.pnghttps://example.com/images/a%20b.png
https://www.example.com/docs/starthttps://example.com/docs/start, after a valid TLS connection

For any non-GET test, use an inert staging route and dummy data. Confirm what method the destination sees and verify that the request does not trigger a real action.

Finally, test the plain HTTP listener from a fresh client even if the browser appears to upgrade the URL automatically. HSTS directs a client that knows the policy to use HTTPS; it does not test the HTTP redirect that a different client might receive.

Sources and further reading

About the author(s)

Software Developer & Writer • Namefi
FBAuthor

Fenwei Bian is a software developer in her thirties who spends her working hours in pull requests and her weekends with her hands in soil or sawdust. Years of open source on GitHub taught her that names are interfaces: a good one is clear, honest about what it does, and kind to whoever has to use it next.

She gardens because it rewards patience and punishes wishful thinking, and she does woodwork because a joint either fits or it doesn't. Both habits show up in how she writes about naming — measure twice, check the source, and don't sand over a rough spot and hope no one notices.

For Namefi she writes about how domain markets actually move, the practical trade-offs of tokenizing and flipping names, and picking a domain you'll still be glad you own in twenty years.

Related guides

Discuss this post

View the discussion on Namefi Discuss