3

How can i redirect multiple subdomain to one specific subdomain using CloudFlare page rule.

Note: redirect without changing the URL path (only sub domain change)

For example:

  • sub1.site.example/article
  • sub2.site.example/article
  • sub3.site.example/article

into:

newsub.site.example/article


If any of the 3 examples URLs is typed in browser, it should automatically redirect to newsub.site.example

How can this be done using cloudflare page rule? Please help

5
2

Cloudflare has the documentation about page rules here: https://support.cloudflare.com/hc/en-us/articles/218411427-Understanding-and-Configuring-Cloudflare-Page-Rules-Page-Rules-Tutorial-

You might be able to use a single page rule to do this, if you don't mind redirect any subdomain that starts with sub. You could use two wildcards, one for number in the subdomain and the other for the URL path. The first wildcard becomes $1 and the second becomes $2. Because you are discarding information about the subdomain, you would not use $1 in the resulting URL, but you would use the $2 to preserve the path:

If the URL matches: sub*.site.example/*
The settings are: Forwarding URL, 301 Permanent Redirect
newsub.site.example/$2

If your subdomains don't match a pattern, or if you have other subdomains that you want to keep that fit the pattern, you would need to use multiple page rules. With multiple page rules you only use one wildcard, so the path is $1 is the resulting URL. A free Cloudflare account only gets three page rules, so this would use up all of them.

If the URL matches: sub1.site.example/*
The settings are: Forwarding URL, 301 Permanent Redirect
newsub.site.example/$1

If the URL matches: sub2.site.example/*
The settings are: Forwarding URL, 301 Permanent Redirect
newsub.site.example/$1

If the URL matches: sub3.site.example/*
The settings are: Forwarding URL, 301 Permanent Redirect
newsub.site.example/$1

5
  • Wooow dude you are a legend 💕🙏✨
    – Bryan tv
    Aug 8 '21 at 8:37
  • I just try it but it say forwarding url matches target would cause redirect loop
    – Bryan tv
    Aug 8 '21 at 8:49
  • My sub domains is ww1.nktube.ga ww2.nktube.ga and ww3.nktube.ga, i want all the three to point to ww4.nktube.ga with path please legend help me with this
    – Bryan tv
    Aug 8 '21 at 9:23
  • You can't use the first option with the wild card in the subdomain because the wild card matches the new subdomain as well. You'll have to use the three separate rules. Aug 8 '21 at 10:50
  • Ok thanks a lot for your helps legend🙏✨
    – Bryan tv
    Aug 8 '21 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.