I have a question regarding the URLs of a website developed with CodeIgniter which offers content in two different languages: en and de
I would like to create SEO friendly URLs for both languages.
My question:
How can I change following URL
www.mysite.com/en/landscape
in
www.mysiste.com/de/landschaft
for German?
Use the codeigniter language library with this class extension: URI Language Identifier . 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.