Implementing Vanity URLs in PHP w/ Zend Framework

One of the reasons why people like vanity url’s is because they are easy to remember. For example take the following url:

http://www.somesocialsite.com/?user_id=123456789&page=somepage

If this was the url to my page in some social network site, there’s no way I could remember it nor would I be able to easily share the url with others unless I sent them the link. Now, if I could instead create a vanity url that looked like the following:

http://www.somesocialsite.com/joeyrivera

it would be much easier to remember and to share with others. Not only that but now I have a much more search engine friendly url with keywords that I would like to be found under – but ignore the search engine benefits for now.

Why

I’m currently working on an application that can benefit from vanity urls for the reasons mentioned above so I decided to spend some time thinking of ways to implement this. The first way that came to my mind was using mod_rewrite. Mod rewrite lets you manipulate urls. For example, you can write rules in your .htaccess file so when a user goes to http://www.somesocialsite.com/joeyrivera it really calls http://www.somesocialsite.com/search.php?user=joeyrivera or in zend the request would be more like http://www.somesocialsite.com/search/user/name/joeyrivera Continue reading “Implementing Vanity URLs in PHP w/ Zend Framework”