Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

url rewriting - Yii, change homeUrl

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!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
        }
        ---
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...