In a Zend Framework 2 app I have two languages, ‘nl’ (default) and ‘en’. Request url’s for ‘nl’ are like:
/controller/action
and for ‘en’ like:
/en/controller/action
First I want to route/rewrite the default language to:
/nl/controller/action
in order to be able to subsequently use a segment route like:
[:lang/[:controller/[:action]]]
I tried this with the below regex route (with negative look ahead)
'lang' => array(
'type' => 'Zend\Mvc\Router\Http\Regex',
'options' => array(
'regex' => '/(?!en)(.*)',
'spec' => '/nl$2',
),
),
(this route should not map to a controller/action but should only rewrite the url to a new one)
But I get:
Page not found.
The requested controller could not be mapped to an existing controller class.
What would be a correctly functioning route? Or is it better to use a web server rewrite?
A regex route is not necessary, the below works as well. The language segment is optional. In my application it can only be ‘en’ and if it is omitted, the default is ‘nl’: