简体   繁体   English

CodeIgniter:如何在多语言网站中更改 URL 名称

[英]CodeIgniter: how to change URL name in a multilingual website

I have a question regarding the URLs of a website developed with CodeIgniter which offers content in two different languages: en and de我有一个关于使用 CodeIgniter 开发的网站的 URL 的问题,该网站提供两种不同语言的内容: ende

I would like to create SEO friendly URLs for both languages.我想为两种语言创建 SEO 友好的 URL。

My question:我的问题:

How can I change following URL如何更改以下网址

www.mysite.com/en/landscape www.mysite.com/en/landscape

in

www.mysiste.com/de/landschaft www.mysiste.com/de/landschaft

for German?对于德语?

Use the codeigniter language library with this class extension: URI Language Identifier .使用带有此类扩展的 codeigniter 语言库: URI 语言标识符 I also use this controller for switching the language我也用这个控制器来切换语言

class LangSwitch extends CI_Controller {

public function __construct() {
    parent::__construct();      
}
public function switchLanguage($language = "") {

    $this->load->library('user_agent');
    $referrer = $this->agent->referrer();

    $l = substr($referrer, strlen(base_url()));

    if(isset($referrer)){
        preg_match('/\/(.+)$/i',$l,$match);
        $redirect_url;
        if (empty($match)) {
            redirect(base_url().$language ,'refresh');
        }
        else{
            $redirect_url = base_url().$language.$match[1];
        }
        redirect($redirect,'refresh');
    }else{
        redirect(base_url(),'refresh');
    }
  }
}

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM