Redirect only if URI Path is an integer?

What is the name of the domain?

example.com

What is the issue you’re encountering

Having trouble generating the expression to match based upon a number

What are the steps to reproduce the issue?

I’m trying to create a rule so that a request coming in to https://example1.com/[number] is redirected to https://example2.com/thipath/[number] but I don’t seem to be able to get a Redirect Rule to do this.

The best I can do is a Page Rule, but that matches anything as the URI, as opposed to just if the URI only contains an integer.

Thanks for any advice or hints!

If you have at least a Business plan, that should be easy with a regular expression. Otherwise it’s essentially impossible to implement. You could go the Worker route, but probably handle it best on the server.

1 Like

Untested, but you can try this if you have a Business plan

concat("https://example2.com/thipath/", regex_replace(http.request.uri.path, "^/(\\d+)", "${1}"))
2 Likes

Or, if on a Pro plan or higher, a Snippet instead of a Worker is ideal, and designed, for this sort of thing…

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.