-1

i've a multilanguage site. I've set up the .htaccess and urlmanager rules, and they correctly works. One last thing remain

I want that direct visit to www.mysite.com auto append the language in this way:

 www.mysite.com -> www.mysite.com/en/ or obviously to www.mysite.com/fr/ etc etc

Now with my rules, after the first access to the home, all the links to the home thanks to ovverriden createUrl correctly became www.mysite.com/en/ but not the first access in case a user directly wrote in the browser www.mysite.com

How can make also the first access url to became www.mysite.com/en/?

I can assign a default language in case the aren't no cookie or no session or no GET or POST params.

Help me!!

user2548436
  • 915
  • 2
  • 16
  • 35
  • Check out this question which is very similar http://stackoverflow.com/questions/20587170/yii-urlmanager-append-language-on-homepage – The Humble Rat Dec 14 '13 at 21:55

2 Answers2

1

If your default Controller is site/index, then you can do like this.

 public function actionIndex() {
        if(!isset($_GET['lang'])){
            $this->redirect(array('site/index','lang'=>'de')+$_GET); // 'de' is considered as default language
        }
        ---
    }
Chaulagai
  • 752
  • 8
  • 12
0

in your application/index.php do as following so that you can redirect it to your custom host.

$client = strtolower($_SERVER['SERVER_NAME']);
$newURL = 'www.mysite.com/en/';

if ($client == 'www.mysite.com') {
   header('Location: '.$newURL);
}

Ref : How to make a redirect in PHP?

Community
  • 1
  • 1
dev1234
  • 5,376
  • 15
  • 56
  • 115