Working with URLs
- Last updated on August 10, 2020 at 10:36 PM
In some areas of Elevio management, you can enter in a URL for things like custom per page settings.
Sometimes when adding URLs you want more control rather than simply an exact match of what you enter, or perhaps you're not getting the match you need when things look right at first glance.
Let's look at some examples.
Wildcards
If you are creating custom settings for a page with the URL of:
Perhaps you want it to match all products though, not just the product with the product with the ID of 1. How do we do that?
This is where what's known as "regular expressions" come in. If you're not familiar with regular expressions (or regex for short), it can be quite overwhelming at first. Luckily, you don't need to be a regex master to do what you need here.
The quickest solution to the above, is to use a wildcard, which in regex is (.*), which matches everything. So the URL you can use for matching would be:
https://mysite.com/product/(.*)
Ignoring the query string
Another example might be if you have links coming to your product from marketing campaigns, or some internal identification system or something similar, where you end up having a query string on the end of the url (a query string is essentially anything that you see in a URL that is after a "?" character, it's extra information that gets passed to the page).
We don't ignore query strings by default, as they can actually be quite useful in setting up your pages and showing different helpers based on the information on the query string.
A legitimate example might be:
https://mysite.com/product?id=1
But, if you want to ignore the query string on a given page that may or may not be there if it's irrelevant and getting in the way, you can do something like this:
https://mysite.com/product(\?.*)?
I know this looks strange (welcome to the world of regex), but basically what it's saying is:
- Match on anything that starts with https://mysite.com/product,
- then a question mark and a wildcard (like earlier)
- but that is optional (the final question mark means "optional")
Need more help?
The above are two very common situations, but if you need help with something more complex. Reach out, and we'll see if we can help get you what you need.