Using Wildcards in Page Rules

The basic page rule

If we have a page rule set to match:

example.com

It will match both http://example.com and https://example.com. You do not need to specify http:// or https:// to match in the page rule, unless you want to limit it to only trigger on that protocol. You do not need a wildcard (*) to match both http and https.


Wildcards

In page rules, the asterisk (*) can be used as a wildcard, for instance, if we have a page rule set to match:

example.com/a*z

It will match example.com/abcdz and example.com/axyz, the asterisk means it will match any subdirectory beginning with a and ending with z

Wildcard examples

example.com/*
would match https://example.com/anything or http://example.com/anything , but NOT a subdomain of example.com like subdomain.example.com .

Adding another wildcard before, such as:
*example.com/*
would match anything before the example.com as well, for example it would match https://example.com and also subdomain.example.com

Adding a dot after the first wildcard, such as:
*.example.com/*
would match anything before the example.com , but not example.com itself. It would match subdomain.example.com , but NOT example.com


Use with ‘Forwarding URL’

The page rule wildcards can be useful to match a section of your website or those of a certain file type, however it can also be useful when redirecting using the ‘Forwarding URL’ setting. It can then be used alongside the $ symbol in the URL to forward to.

For example, if you set:

example.com/*
Forwarding URL
https://www.example.com/$1*

This would match any path on example.com and redirect it to the same path on www.example.com. E.g. example.com/abc would redirect to https://www.example.com/abc.

You can use $1, $2, $3 etc. to match any *.

You can read more in the tutorial, Using page rules to perform redirects.



Note that an ‘Orange Clouded’ DNS record is required for a page rule to run

For example:
If I wanted a page rule to match subdomain.example.com, then I would need to add a DNS record for subdomain and set it to :orange:.


Relevant support article:



This is a Community Tutorial , most are wiki posts, so can be contributed to by Regulars and MVPs here, you can view all the community tutorials here . If there is a tutorial you would like to see, you can request one here .

Other great resources on this community include the Community Tips . These address best practices when configuring Cloudflare, how to fix issues you may see, and tools to troubleshoot. Also you can view Expert Tips, great posts on the community that can help users with a similar issue.

We encourage users to check out these great resources and the Cloudflare Support Centre before posting