Introduction
Regular expressions (or Regex) are a powerful tool for precisely targeting pages in Fasterize.
They allow you to create conditional configuration rules, for example, to apply certain optimizations to a specific set of URLs, or to exclude certain ones.
Using the “Matches a regex” option in the rule creation interface, you can define very specific dynamic URL patterns. Let’s take a look at how this works, using some concrete examples.
Understanding the Basics of Regular Expressions
A regular expression is a sequence of characters that describes a text pattern.
This allows you to say, for example: “I want to target all URLs that start with /products/ “and end with a word.”
💡 In short: A regex is a smart filter based on the structure of a text (in this case, your website’s URLs).
Let's take a simple example:
The Regex ^/products/.* means:
^→ starts with/products/→ this fixed path.*→ followed by any characters, as many as you like
This allows you to target all the pages in the "Products" section of a website.
Key Elements of Regular Expression Syntax
Here are some useful basics for writing your own regular expressions:
💡 Basic Glossary:
- Special characters
.: any character^: Start of the chain$: end of line\\d: number (0to9)\\w: alphanumeric character\\s: blank space
- Quantifiers
- : 0 or more times
+: 1 or more times?: 0 or 1 time{n}: exactly n times{n,}: at least n times{n,m}: between n and m times
- Character sets
[abc]: one character froma,borc[a–z]: any lowercase letter[^abc]: anything buta,borc
Apply a regular expression in Fasterize
In Fasterize, you can use a regular expression:
- to target specific pages (conditional application of a setting)
- or to exclude certain pages from optimization
In the interface, this is done through the rule configuration menu by selecting the “Matches a regex” option from the list of targeting types.
Example of use: You want to exclude pages /blog/ For HTML minification, create a rule using:
- Condition: URL → Matches a regular expression →
^/blog/.* - Action: Disable HTML optimization
Practical examples of regular expressions for your pages
Here are some practical examples of how to use regular expressions for an e-commerce site:
Target all product pages
URL format: /products/product-name
Regex: ^/products/.*
Matches all pages whose URL begins with /products/.
Target a single product page
URL format: /single-product
Regex: ^/product-only$
Matches exactly this URL, and only this one.
Target specific subcategories
URL format: /category1/subcategory2/myproduct
Regex: ^/category1/subcategory2/[^/]+$
Target all pages at this level of depth, without any additional subdirectories.
Target general category pages
URL format: /category1/
Regex: ^/category1/[^/]*$
Ideal for targeting category or product listing pages.
💡 Regex Reference Table:
Use CaseExample URLRegexProduct Section/products/myproduct^/products/.*Specific product page/single-product^/single-product$Category with product subcategory/cat1/subcat2/product^/cat1/subcat2/[^/]+$General category page/category1/^/category1/[^/]*$
Pay attention to the order of the rules in EdgeSpeed
In Fasterize (via the EdgeSpeed engine), the order of the rules is crucial:
The system applies the first rule that matches the request URL.
Let’s take the following example:
- Rule 1:
^/personal - Rule 2:
^/staff
A URL such as /staff also matches ^/personal, so Rule 1 will be applied, even though Rule 2 is more specific.
⚠️ To prevent this behavior, place the most specific rules at the top of the list.
In the correct order:
^/staff
^/personal
Incorrect order:
^/personal
^/staff
Conclusion
Regular expressions are a simple yet powerful tool for fine-tuning your rules in Fasterize.
They allow you to precisely target the pages where you want to apply or disable certain optimizations.
💡 Key takeaway:
- Use
^and$to specify the start and end of a URL - Test your regular expressions before applying them on a large scale
- Follow the priority order of the rules in EdgeSpeed to avoid surprises
For further information, feel free to check out an online testing tool (e.g., regex101.com)
.png)