Well i need to make it so any user can have a foo.com/username in my site where i user a Zend framework.
The thing is that i want foo.com/login and other controllers to keep working as they do, so i already validate that no user can be named as one of the controllers im going to use. The htaccess cant be changed or the mvc configuration wont work. So im using the Router.
I know that if i use something like:
$routes = array(); $routes['entry'] = new Zend_Controller_Router_Route_Regex('SOME REGEX HERE', array( 'controller' => 'profile', 'action' => 'show' ), array( 'id' => 'dsadsa', // maps first subpattern '(\d+)' to 'id' parameter 1 => 'id' // maps first subpattern '(\d+)' to 'id' parameter ) ); $router->addRoutes($routes);
i can make it so everything that matches the regex is redirected, but i dont know if theres a better way(somehow chaining 2 routers) where i dont have to actually list my controllers in a very very big OR.
Any idea?
Something like this should work:
Then add all of your other routes, for /login, /logout, etc. As Tim said, Zend matches routes in reverse order, so it will try to match against your ‘whitelist’ of routes prior to finally sending it to your ‘username’ route.
This will break any type of error checking Zend does for making sure the controller/action exists, since everything will be routed to /profile/show if there are no route matches.
All of this could be easily avoided, however, if you could just deal with foo.com/user/<username>.