Failing to redirect a subdomain to another page (within the same hostname)

Hi, I have a domain whose DNS is controlled by cloudflare and the Cloudflare Pages is serving a static site from Github repo.
Now I am trying to redirect a specific subdomain (https://sub.domain.com) to a specific page (https://domain.com/sub or https://domain.com/sub.html)

I first read:
https://developers.cloudflare.com/fundamentals/basic-tasks/manage-subdomains/
Essentially, I created Rules → Redirect Rules. Where I specified URI Full Path and gave the target address. See
https://drive.google.com/file/d/1b-kT31FYnfVZI6pyn86s0qS9coIoe3Xe/view?usp=sharing

I also added a subdomain to my DNS. I tried both A record with 192.0.2.1 (proxied) and CNAME with the main domain address (proxied). Both didnt work.
https://drive.google.com/file/d/1KFzGXVj29OYkNvTknZxz8w9SfgwRn4qd/view?usp=sharing

In all cases, going to a subdomain (https://sub.domain.com) on a browser gave Error code 522

Is there any fix?

You were so very close to having it match – You just need a / at the end since path is never empty, ex https://conrad.informatism.com/
I would recommend using a more exact match though, for example your match on URI Full would break if there was any query parameters.
Instead, you could do
Hostname eq conrad.informatism.com
and
Path eq /


Less brittle of a match.
If you wanted it to redirect any page on conrad.informatism.com, ex even conrad.informatism.com/gihgghfoigfhgoh, then you could just remove/not add the URI Path check, and just match by hostname alone.

Thank you and it works!
Is there a way to keep the URL from changing? After the redirect, I would like the subdomain URL to stay, as if the content is served from that.

If that’s not possible, is there any way to do so using cloudflare and static site?

You could add conrad.informatism.com as another Pages Custom Domain, and then use a Transform Rule → Rewrite URL (Rewrite URL rules · Cloudflare Rules docs) like this:


(Make sure to remove the redirect rule!)
This isn’t always a safe thing to do due to relative paths, CORS and such, but in your case it looks like it might just work

Thanks!

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