How to redirect to HTTPS before redirect?

I would like to redirect http://domain.com (non-secure) to https://domain.com (secure), then redirect https://domain.com to https://other-domain.com.

Use case: I want to add my domain to HSTS preload list.

Problem: HSTS requires that I redirect from HTTP to HTTPS with same domain first, before redirect to other domain.
Currently, if I add a CNAME for @ pointing to other-domain.com, and enable Always HTTPS, then the CNAME rule is applied and Cloudflare redirect http://domain.com directly to https://other-domain.com, without redirect to https://domain.com first.

How can I config for this use case?

Can you share your domain and also a screenshot of the Redirect / Page Rule you have created for the redirect?

Hi @Laudian, here is the domain and config:

CNAME: tuyen.xyz → tuyen.blog

Page rule for HTTP to HTTPS:

It is the first rule in the page rule list.
(I cannot include the rule list here since I can only include one image per post).

That seems to work exactly as you intend to:

curl -v http://tuyen.xyz
Location: https://tuyen.xyz/

curl -v https://tuyen.xyz
location: https://tuyen.blog/
1 Like

Ah, you’re correct. I check on my PC it doesn’t has same results as yours, but after I run ipconfig /flushdns then I see the expected header.
It seems Windows cached the DNS query before I config the rules, and serves that cache when I check it later.
So it’s working fine now. Thank you for the support.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.