Using RegEx in mapped URLs
Regular Expressions (RegEx), whilst powerful, can be tricky to work with so if you aren't comfortable with RegEx or don't have a basic working knowledge of how to use it, consider learning more about it and experimenting using tools such as RegExr.
When entering a URL for a mapping, it is possible to use RegEx patterns to match incoming requests dynamically. This makes it possible to:
- Serve the same mapped resource across multiple URLs in one mapping.
- Redirect many URLs in one mapping.
By default, URLs entered into the path field are treated as exact matching. If, however, you check the RegEx checkbox below the URL field, the mapping has the potential to map to many requested URLs.
Basic Examples
my/custom/*will match against many inbound requests including (but not limited to):http://example.com/my/custom/http://example.com/my/custom/thishttp://example.com/my/custom/this/thathttp://example.com/my/custom/this/that/otherhttp://example.com/my/custom/thistle
my/custom/[0-9]+will only match when there are one or more digits at the end. Consider the following:http://example.com/my/custom/1would match.http://example.com/my/custom/123would match.http://example.com/my/custom/12345678would match.http://example.com/my/custom/thingwould NOT match.http://example.com/my/custom/123/thingwould NOT match.
A note on delineating the end of URLs
Be mindful that when using RegEx, the end of the URL isn't clear unless strictly stated and without marking the end of the URL in your match pattern, you may end up with unintended side effects. Consider the following (in this example, the regular expression checkbox is enabled):
my/custom/url will match against any requested path starting with my/custom/url. i.e;
http://example.com/my/custom/urlhttp://example.com/my/custom/url/http://example.com/my/custom/url-pagehttp://example.com/my/custom/url/page
To correctly mark the end of your match pattern
In order to specify the end of your URL, use the $ symbol. For example:
my/custom/url$ will match against http://example.com/my/custom/url but it won't match against http://example.com/my/custom/url-page.
