So, I have the following rows in the DB:
1 | /users/
2 | /users/admin/
3 | /users/admin/*
4 | /users/admin/mike/
5 | /users/admin/steve/docs/
The input URL is /users/admin/steve/, and the goal is to find the URL match from the DB.
I want to return #3 as the correct row, since the wildcard "*" specifies that anything can go in place of the asterisk. What would be the most efficient method for doing this?
Here's my initial thoughts, but I'm sure they could be improved upon:
- Make a query to see if there's an exact URL match
- If no matches, then retrieve all rows with "*" as the last character, in reverse order (so the more specific URLs take precedence)
- For each row, if it (minus the "*") matches the input URL, then return it
- If nothing is found, then we're SOL