I am using elangurlmanager for creating multilanguage site but it produces non seo friendly urls even when I wanna add additional parameters in my urls.
'rules'=>array(
''=>'site/index',
//'<action:[\w\-]+>' => 'site/<action>',
//'<lang:\w+>/<action:[\w\-]+>' => '<lang>/site/<action>',
'<controller:\w+>/<action:\w+>/<alias:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>/<id>',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
),
this is my config file and in elangurlmanager there is said that we don’t need to add language in this rules.
this is that extension elangurlmanager
joblo
(Joe)
May 20, 2014, 7:37am
2
Replace the method addLanguageUrlRules (this is my latest one, not published).
Do a
var_dump($rules); die();
(or debug) to see what rules will be added.
Then you can try without ELangUrlManager and add these rules manually.
/**
* For seofriendly url routes
* Adds the rules
* '<languageParam:(lang1|lang2|...)>'=>'/'
* '<languageParam:(lang1|lang2|...)>/'=>'/'
* '<languageParam:(lang1|lang2|...)>/<route:[\w\/]+>'=>'<route>'
*
* Called in method init()
*
*/
public function addLanguageUrlRules()
{
if (!$this->_languagesRuleAdded && $this->languagesEnabled())
{
$languages = $this->languages;
$curLanguage = Yii::app()->language;
if (!isset($languages[$curLanguage]))
$languages[$curLanguage] = $curLanguage;
$rule = '<' . $this->languageParam . '<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />';
foreach ($languages as $language=>$label)
$rule .= $language . '|';
$langRoute = substr($rule, 0, -1) . ')>';
$rules[$langRoute] = '/';
$rules[$langRoute . '/'] = '/';
$rules[$langRoute . '/<_route:.*>/*'] = '<_route>';
var_dump($rules); die(); //<---------- check the added rules
$this->addRules($rules, false);
$this->_languagesRuleAdded = true;
}
}
Joblo:
Replace the method addLanguageUrlRules (this is my latest one, not published).
Do a
var_dump($rules); die();
(or debug) to see what rules will be added.
Then you can try without ELangUrlManager and add these rules manually.
iot outputs this.
array(3) { [""]=> string(1) "/" ["/"]=> string(1) "/" ["/"]=> string(7) "" }
joblo
(Joe)
May 20, 2014, 8:39am
4
Do you have languages assigned as language=>label in config/main.php?
'urlManager'=>array(
'class'=>'ELangUrlManager',
'languages'=>array('de'=>'Deutsch','en'=>'English'), //assoziative array language => label
),
...
)
Joblo:
Do you have languages assigned as language=>label in config/main.php?
'urlManager'=>array(
'class'=>'ELangUrlManager',
'languages'=>array('de'=>'Deutsch','en'=>'English'), //assoziative array language => label
),
...
)
Yes ‘languages’=>array(‘am’=>‘Հայ’,‘ru’=>‘Рус’, ‘en’=>‘Eng’), //assoziative array language => label
Joblo:
Replace the method addLanguageUrlRules (this is my latest one, not published).
Do a
var_dump($rules); die();
(or debug) to see what rules will be added.
Then you can try without ELangUrlManager and add these rules manually.
/**
* For seofriendly url routes
* Adds the rules
* '<languageParam:(lang1|lang2|...)>'=>'/'
* '<languageParam:(lang1|lang2|...)>/'=>'/'
* '<languageParam:(lang1|lang2|...)>/<route:[\w\/]+>'=>'<route>'
*
* Called in method init()
*
*/
public function addLanguageUrlRules()
{
if (!$this->_languagesRuleAdded && $this->languagesEnabled())
{
$languages = $this->languages;
$curLanguage = Yii::app()->language;
if (!isset($languages[$curLanguage]))
$languages[$curLanguage] = $curLanguage;
$rule = '<' . $this->languageParam . '<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />';
foreach ($languages as $language=>$label)
$rule .= $language . '|';
$langRoute = substr($rule, 0, -1) . ')>';
$rules[$langRoute] = '/';
$rules[$langRoute . '/'] = '/';
$rules[$langRoute . '/<_route:.*>/*'] = '<_route>';
var_dump($rules); die(); //<---------- check the added rules
$this->addRules($rules, false);
$this->_languagesRuleAdded = true;
}
}
this worked thank you very much!
Shouldn’t you tell Elangurlmanager extension makers to change their code to this latest one in order to everyone can use it without any issues?
joblo
(Joe)
May 20, 2014, 10:43am
7
Ok, I’ll update the extension.