Let’s say I’m building a web application whose user pages can be found at http://example.com/NAME. What’s the best way to make sure the username doesn’t conflict with a reserved word (e.g. ‘about’, ‘contact’, etc.)? I can think of two ways:
- Maintain a list somewhere in my code. This is great and all, but means I have another piece of code I have to edit if I decide to, say, change the “about” page to “aboutus”.
- Request the URI (e.g. http://example.com/someusername) and check if it exists (doesn’t return a 404). This feels kind of like a hack, but on the other hand it does exactly what it’s supposed to do. On the other hand, I can’t reserve anything without making a page for it.
What would be the best way to go about this? Manual validation of usernames is not an option. Thanks!
EDIT: I forgot to mention, the username has to go at the root, like this:
Not like this:
Hence why I’m asking this question. This is for technical reasons, don’t ask.
In the interest of completeness, if you can’t change the routing. Another possibility is to have your user routes and your non-user routes have a programmatic distinction. For example, if you appended a
'_'to the end of each of your user routes, then you can make sure that users are located at: http://example.com/NAME_ and the other route would never end in'_'