yassineqoraiche's avatar

Wildcard redirection rules

Hello guys, we are currently saving redirection rules in our database as follows:

https://i.stack.imgur.com/YY25M.png

so basically, there are inputs where you add the Redirect 'FROM' and Redirect 'TO' endpoints and save it to the database so that when you access an URL we have a function that will check if we have the current URL path in the database if so, we will redirect it to the 'TO' endpoint:

currently, it only supports the full relative paths redirect.

so my question is how can I achieve wildcard redirect star standing for "whatever", and make a substring match. Or use the LIKE operator in SQL.

https://i.stack.imgur.com/GGIl6.png

0 likes
1 reply
automica's avatar

Can you show method you are currently doing for your redirection?

If you are trying to intercept requests to determine your request route, then you can add a middleware to do this.

For your wildcard matches, if your * is your last character of the input string, you’ll want to strip that and then do a LIKE against the FROM url in your database which will provide a match to redirect to.

If you don’t want to hit the db for every request, you could store the routes to a cache when you add or amend your routes table and then load the data from there in your middleware.

1 like

Please or to participate in this conversation.