I've seen this asked on the mailing lists as well, so I've put up a blog post with a detailed example of how to achieve this in ZF using a custom route class, see:
http://tfountain.co.uk/blog/2010/9/9/vanity-urls-zend-framework
This might not be the simplest approach, but in my opinion it is the best, as it allows you to setup a username route like any other, and you can still use the standard ZF URL helpers and other routing toys.
The only other option is to extend the standard ZF router and then check for a username route before doing anything else. Something like:
class My_Router extends Zend_Controller_Router_Rewrite
{
public function route(Zend_Controller_Request_Abstract $request)
{
$pathBits = explode('/', $request->getPathInfo());
if (!empty($pathBits[0])) {
// check whether $pathBits[0] is a username here
// with a database lookup, if yes, set params and return
}
// fallback on the standard ZF router
return parent::route($request);
}
}
You then need to tell the front controller to use your router instead of the default one, so in your bootstrap:
protected function _initRoutes()
{
Zend_Controller_Front::getInstance()->setRouter(new My_Router());
}
replace 'My' with your application's own namespace.
If you follow this approach you can't use the URL helper for your username routes, and things can become a bit messy if you start needing to add other custom functionality, so go with the custom route class instead.