Yii urlmanager,在主页上附加语言 [英] Yii urlmanager, append language on homepage

查看:30
本文介绍了Yii urlmanager,在主页上附加语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下网址规则:

            '<lang:(it|de|en|fr|es)>' => 'site/index',
            '<lang:(it|de|en|fr|es)>/search' => 'site/search',                              
            '<lang:(it|de|en|fr|es)>/<action:(page|logout)>/*' => 'site/<action>',                                                      
            '<lang:(it|de|en|fr|es)>/<controller:\w+>' => '<controller>/index',                
            '<lang:(it|de|en|fr|es)>/<controller:\w+>/<action:\w+>/*' => '<controller>/<action>',               
            '<lang:(it|de|en|fr|es)>/<module:\w+>/<controller:\w+>/<action:\w+>/*' => '<module>/<controller>/<action>',

它们按我的需要工作,但还有最后一个问题.

and they work as i need, but one last problem.

通过此规则,我已实现以这种方式将语言附加到所有网址:www.mysite.com/it/CONTROLLER/ACTION

With this rules i've achieved to attach the language to all url in this way: www.mysite.com/it/CONTROLLER/ACTION

第一次访问时问题仍然存在,如果用户直接在浏览器中写入网站网址,他会转到 www.mysite.com 而不是 www.mysite.com/userlanguage/:(

The problem remain on the first visit, if a user wrote directly the website url in browser, he go to www.mysite.com AND NOT to www.mysite.com/userlanguage/ :(

通过这种方式,我有 3 个重复的主页网址,它们是:

In this way i've 3 duplicated urls for the home page that are:

 www.mysite.com
 www.mysite.com/userlanguage/
 www.mysite.com/index.php

我需要将所有这些重定向到 www.mysite.com/userlanguage/

and i need to redirect all of this to www.mysite.com/userlanguage/

我需要为语言提供一个不同的一页网址.

My need is to have one different one page url for language.

遵循.htaccess

Following the .htaccess

  RewriteEngine on
  #LOCAL


  RewriteBase /mydir/subdir/

  # if a directory or a file exists, use it directly
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteCond %{REQUEST_URI} !=/favicon.ico
  # otherwise forward it to index.php
  RewriteRule . /index.php

  AddDefaultCharset utf-8

谁能帮帮我?谢谢

推荐答案

如果你的默认控制器是站点/索引,那么你可以这样做.

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

这篇关于Yii urlmanager,在主页上附加语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆