I recently posted a question about creating vanity URLs on my site and while I got many great answers, I am curious to see what was wrong with my original idea:
Here is the problem:
I currently have ugly URLs that look like this:
http://www.hikingsanfrancisco.com/hiker_community/hiker_public_profile.php?community_member_id=2
What I want is something elegant like this:
http://www.hikingsanfrancisco.com/alex-genadinik
What my proposed solution is:
Can I just store “alex-genadinik” in the database (instead of MVC controllers) and fetch the vanity URL when look up the person. And then I could redirect to the elegant-looking domain?
Or will the redirection add a level of technical-awkwardness and inflexibility? Maybe I wouldn’t have to redirect at all. I mean I’d be looking things up in the db instead of the server. I think thats the only difference. Thoughts? 🙂
There’s nothing wrong with your proposed solution. In fact WordPress can be configured to do exactly this.
I would implement it as follows (similar to WordPress):
non-existant files that are
requested, and rewrite to your
router.php
check the for this non-existant path
in your db, against a list of pre-calculated vanity names.
relevant information, if not return
a set of 404 headers to show that neither the file or the vanity name exist.
URL Rewriting Guide