I'm looking for a way to modify a request URL before it gets dispatched. For instance, the following URLs should be handled by the same controller/action:
/en/paris
/de/paris
/paris
I would like to capture the country code if it is present, then rewrite the URL without it so that controllers don't have to deal with it. I tried the 'dispatch:beforeDispatchLoop' event but it doesn't seam to be designed for that.
Any idea?
If you can convention that all country code comes first in the path, perhaps an additional rewrite rule can help you:
EDIT
If you really need to do this in PHP, I'd recommend you to intercept the country code at the earliest to not break the default routing behavior (i.e need to write all routes manually). One way to do this is by setting a shared service in your main DI to replace the default
'router'
service. The customized router consist simply in a child of Phalcon\Mvc\Router with the method getRewriteUri overridden by something that does whatever you want them just return the URI without the country code part: