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
  • To clarify you want exactly those three subdomains to redirect or every subdomain except newsub? Commented Aug 7, 2021 at 23:44
  • Is Cloudflare configured as the CDN for your newsub subdomain? Commented Aug 7, 2021 at 23:45
  • Yes i want those 3 subdomain to redirect to newsub
    – Bryan tv
    Commented Aug 8, 2021 at 2:46
  • yes cloudflare is used as cdn
    – Bryan tv
    Commented Aug 8, 2021 at 2:47
  • Here is an example of a live website if you type this address: w1.voirfilm.plus/films/breach-2021.html it automatically redirect to ww1.voirfilm.plus/films/breach-2021.html keeping the path, i want to know how to do this please help me
    – Bryan tv
    Commented Aug 8, 2021 at 2:52

1 Answer 1

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
    Commented Aug 8, 2021 at 8:37
  • I just try it but it say forwarding url matches target would cause redirect loop
    – Bryan tv
    Commented Aug 8, 2021 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
    Commented Aug 8, 2021 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. Commented Aug 8, 2021 at 10:50
  • Ok thanks a lot for your helps legend🙏✨
    – Bryan tv
    Commented Aug 8, 2021 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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