Revision #31 has been created by oligalma on Dec 12, 2021, 12:48:44 PM with the memo:
General changes
« previous (#30)
Changes
Title
unchanged
How to have truly multilingual URLs
Category
unchanged
How-tos
Yii version
unchanged
1.1
Tags
unchanged
URL,multilanguage,multilingual,multilingual url,multilanguage url
Content
changed
#Introduction
------------------
We can easily have a multilingual site if we put a "lang" parameter that comes via GET. For example:[...]
```php
<?php
echo CHtml::link('TutorialDownloads', array('/site/
tutorialdownloads', 'lang' => 'en'));
echo CHtml::link('
Tutoriales', array('/site/tutorials', 'lang' => 'es'));
echo CHtml::link('Services', array('/site/services', 'lang' => 'en'));
echo CHtml::link('Servicios', array('/site/serviceDescargas', array('/site/downloads', 'lang' => 'es'));
?>
```[...]
```
#The problem
-----------
This leads to URLs like these:[...]
This is fine to have a multilingual site. But, we can go one step further. What if we want URLs like these:
- http://www.oligalma.com/en/downloads (English)
-
http://www.oligalma.com/es/descargas (Spanish)
That is, every URL has its particular path. It changes the whole URL, not just the two initial letters (en/es).
#The solution
------------
```php
'urlManager'=>array(
'matchValue'=>true,[...]
'showScriptName'=>false,
'rules'=>array(
'<lang:\w+>'=>'site/index',
'<lang:e
sn>/
tutorialedownloads'=> 'site/
tutorials',
'<lang:en>/tutorials'=> 'site/tutorials',
'<lang:es>/servicios'=> 'site/services',
'<lang:en>/services'=> 'site/services',
downloads',
'<lang:es>/descargas'=> 'site/downloads',
'<lang:\w+>/<action>' => 'site/<action>',
)
),
```
(Take note that we also added **'matchValue' => true** to the urlManager array.)[...]