We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

language in url and translated routes


i want to have my routes follow this format www.domain.name/language/controller/action/etc so for english we have www.domain.name/en/products/list/etc for italian we have www.domain.name/it/prodotti/listino/etc if i call www.domain.name/it/products/list/etc should not work

i'm not sure how to explain better

is this kind of thing possible with phalcon ? how would you do this ?

thanks in advance for any help


You can create your routes that way:


$router = new Phalcon\Mvc\Router(false);

$router->add('/{language:[a-z]+}/:controller/:action', array(
    'controller' => 2,
    'action' => 3

$router->add('/{language:[a-z]+}/:controller/:action/:params', array(
    'controller' => 2,
    'action' => 3,
    'params' => 4


thanks i will try and come back if i have problems

I know that this discussion is rather old, but I've the same problem that quasiperfect had. The answer from phalcon reports exactly what I had done in my project, but there is one thing I did not understand: how do you translate the url without duplicating controllers and actions for each language?

I have followed also this discussion: forum.phalcon.io/discussion/1527/multilingual-routing I am not sure, however, if that is the best answer for me; it use a redirection, but I want to use only one request. Is there in Phalcon a tool to do that?

Thank you very much.