I am afraid using Regex, matches, would require a Business or Enterprise plan:
If you’re using a Pro plan, I guess using Snippets could be achievable as well.
However, it is possible using Workers as well on a Free plan as follows from below:
Worker code:
addEventListener('fetch', event => {
const url = new URL(event.request.url);
const orderNo = url.searchParams.get('order_no');
// Regex to match the order_no format "XX-XXXXXX", 2 numbers followed by the dash then 6 numbers
const regex = /^\d{2}-\d{6}$/;
if (orderNo && regex.test(orderNo)) {
// Redirect to the new URL if it matches the pattern
const newUrl = `https://www.mywebsite.com/order/${orderNo}/`; // or what ever the new URL should contain those numbers or what?
event.respondWith(Response.redirect(newUrl, 301));
} else {
// If it doesn't match, continue with the request
event.respondWith(fetch(event.request));
}
});
I’ve tested this on my Website and it does work.
Redirects me when I have 2 numbers followed by the dash then 6 numbers, rather matches e.g. order_no=00-123456 but not order_no=abc-123456 nor ab-123456 nor some other combination. If I have something different, it just proceeds forward with the request (or should throw some origin 404 depends how your environment and web application is configured with your web server).
You have to bound this Worker to your zone/domain and add your Worker route as https://form.nutripath.com.au/forms/pqsaliva/*. Then, in your Worker code change the part of the new URL to which it should redirect (mywebsite.com/order/...).
Or maybe from your topic title, vice-versa we need to fetch? (then the if-else is just vice-versa in the above code, meaning else if it doesn’t match then respond and redirect with newUrl 301).