bulldoze
(Chris)
1
Hello
Im making multilanguage website. I have so far used Yii2 Locale URLs extension (https://github.com/codemix/yii2-localeurls) by Codemix to make urls like:
/en/contact
/de/contact
But this extension has one major problem when i want full SEO website. I cant translate controllers and actions like this:
/en/contact -> site/contact
/de/kontakt -> site/contact
Im sure im not the only one who needs this kind of solution. Can anybody help me or suggest better extension? Any ideas?
phtamas
(Phtamas)
3
Can be done manually in UrlManager konfig:
'urlManager' => [
[
'class' => 'yii\web\GroupUrlRule',,
'prefix' => 'en',
'routePrefix' => '',
'ruleConfig' => ['defaults' => ['language' => 'en']],
'rules' => [
'contact' => 'site/contact',
'about-us' => 'site/about-us',
],
],
[
'class' => 'yii\web\GroupUrlRule',,
'prefix' => 'de',
'routePrefix' => '',
'ruleConfig' => ['defaults' => ['language' => 'de']],
'rules' => [
'kontakt' => 'site/contact',
// and so on...
],
],
],
\yii\helpers\Url::toRoute(['site/contact', 'language' => \Yii::$app->language]);
or, if you have a large website with hundreds of routes, you might want create a custom CompositeUrlRule implementation.