How to Use URL Patterns in Plumrocket Extensions

We have developed URL patterns to easily adjust the extension’s logic to the specific category or set of pages. We use them in many extensions, such as AMP, Popup Login, Cookie Consent, and others to enable or disable some functionality only on specific pages.

Please note that this documentation applies to Magento 2 Base extension v2.9.0 and later.

Important information:

Only the URL path is taken into account when checking the pattern. For example, the following URL https://example.com/category/product.html?v=1#reviews will be truncated to /category/product.html.

Note for developers:

You can use Regular Expressions instead of the provided URL patterns by adding the regex:: prefix to the pattern. For example, regex::#\/category\/.*?# or regex::~[/]category[/]?~.

URL Pattern Specification

Use the following special characters in URL patterns:

  • * – matches 0 or more of the preceding characters (equivalent to the .* regular expression)
  • + – matches 1 or more of the preceding characters (equivalent to the .+ regular expression)
  • \ – makes the character non-special, for example, \+ will be considered as +.

If your patterns don’t start with /, *, or + characters, a slash (/) will be automatically added to the beginning to reduce the number of mistakes. Therefore, /category/* and category/* patterns are considered the same.

URL Pattern Examples

Example 1.

The /category/* pattern matches the following URLs:

  • https://example.com/category/product.html
  • https://example.com/category/

However, it does not match the following URLs:

  • https://example.com/category (the end slash is missing)
  • https://example.com/parent-category/category/product.html (there are extra characters before /category/)

Example 2.

The /category/+ pattern matches the following URL:

  • https://example.com/category/product.html

However, it does not match the following URL:

  • https://example.com/category/ (must be at least one character after /category/)
Was this article helpful?