Page Rules Redirection Problem with Subdomains

I’ve set up a Page Rule to redirect subdomains of my domain to specific URLs. The Page Rule has the following configuration:

  • URL Pattern: www.*.mydomain.io/*
  • Forwarding URL (Status Code: 301 - Permanent Redirect)
  • Destination URL: https://www.mydomain.io/test/$1/example

The Issue: The Page Rule functions correctly for most subdomains, except when accessing subdomains without the “www” prefix. To address this, I attempted to add another Page Rule as follows:

  • URL Pattern: *.mydomain.io/*
  • Forwarding URL (Status Code: 301 - Permanent Redirect)
  • Destination URL: https://mydomain.io/test/$1/example

However, when attempting to access a subdomain such as gopro.mydomain.io, it redirects to https://mydomain.io/test/www/example instead of the expected https://mydomain.io/test/gopro/example. Additionally, when accessing mydomain.io directly, it redirects to https://mydomain.io/test/www/example.

DNS Configuration: Here is my current DNS configuration:

  • A Records:
    • mydomain.io: 7X.7X.XX.XX
  • CNAME Records:
    • *.mydomain.io: mydomain.io
    • www.mydomain.io: cname.vercel-dns.com

How can I resolve this issue and enable the ability to access subdomains with or without the “www” prefix, redirecting them to the correct URLs?

This seems to be the result of redirect chain:

From gopro.example.com to example.com, then from there to www.example.com, where your second page rule triggers. Check your origin configuration or any other Cloudflare Rules to see if you have this extra redirect set somewhere.