Unwanted Characters appears on the url when changing the language

Hi all,

i am a bit new at yii, so i need help with some issue i am facing , i am working on awebsite with 2 languages arabic and english the issue comes when a user try to change the language of the web site, "?en?q=ar" "en/pricing/q/ar%2Fpricing" which might cause some issue to the user upon surfing the web site, the issue dosent appear on my localhost, but it appear when i uploaded my site to testing server.

my language selector widget

components/widget/views/languageselector.php




<div id="language-select">

<?php 

    if(sizeof($languages) < 4) {

        // Render options as links

        $lastElement = end($languages);

        foreach($languages as $key=>$lang) {

            if($key != $currentLang) {

                echo CHtml::link(

                     $lang, 

                     $this->getOwner()->createMultilanguageReturnUrl($key));

            } else echo '<a >'.$lang.'</a>';

            if($lang != $lastElement) echo "<hr style='margin:5px auto' />" ;

        }

    }

    else {

        // Render options as dropDownList

        echo CHtml::form();

        foreach($languages as $key=>$lang) {

            echo CHtml::hiddenField(

                $key, 

                $this->getOwner()->createMultilanguageReturnUrl($key));

        }

        echo CHtml::dropDownList('language', $currentLang, $languages,

            array(

                'submit'=>'',

            )

        ); 

        echo CHtml::endForm();

    }

?>

</div>



components/urlmanager.php




<?php

class UrlManager extends CUrlManager

{

    public function createUrl($route,$params=array(),$ampersand='&')

    {

        if (!isset($params['language'])) {

            if (Yii::app()->user->hasState('language'))

                Yii::app()->language = Yii::app()->user->getState('language');

            else if(isset(Yii::app()->request->cookies['language']))

                Yii::app()->language = Yii::app()->request->cookies['language']->value;

            $params['language']=Yii::app()->language;

        }

        return parent::createUrl($route, $params, $ampersand);

    }

}

?>



controller.php




public function createMultilanguageReturnUrl($lang='en'){

    if (count($_GET)>0){

        $arr = $_GET;

        $arr['language']= $lang;

    }

    else 

        $arr = array('language'=>$lang);

    return $this->createUrl('', $arr);

}



also i have followed this article

http://www.yiiframework.com/wiki/294/seo-conform-multilingual-urls-language-selector-widget-i18n/

[color="#006400"]/* Moved from "2.0" to "1.1" */[/color]

It seems to me to be a problem with your urlManager’s rules.

What do you have for the rules?

solved the issue by updating the create multilanguageurl method


public function createMultilanguageReturnUrl($lang='en'){

    if (count($_GET)>0){

        $arr = $_GET;

        $arr['language']= $lang;

    }

    else 

        $arr = $this->createUrl(Yii::app()->controller->id . '/' . Yii::app()->controller->action->id,array('language'=>$lang));

    return $this->createUrl('', $arr);

}