简体   繁体   English

使用Codeigniter的多语言站点

[英]Multi language site using codeigniter

I want to setup a multi language site for my web app. 我想为我的Web应用程序设置一个多语言站点。 But I'm rather confuse on where to start. 但是我对从哪里开始感到困惑。 I'm using Codeigniter and hosted my domain in a cpanel server. 我正在使用Codeigniter,并将我的域托管在cpanel服务器中。

What I want to have is multi language with subdomains such as: 我想要的是带有子域的多语言,例如:

en.abc.com for english
id.abc.com for indonesia

So far, I have set up the advanced DNZ Zone editor and point the subdomains to the server IP address. 到目前为止,我已经设置了高级DNZ区域编辑器,并将子域指向服务器IP地址。 But, I don't know what to do next. 但是,我不知道下一步该怎么做。 I have read on some tutorial to set the .htaccess, etc. But it doesn't work. 我已经读过一些教程来设置.htaccess等。但是它不起作用。

This is my .htaccess file: 这是我的.htaccess文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)\.html$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{HTTP_HOST} ^en\.lokadok\.co.id$
RewriteCond %{REQUEST_URI} !^/en/
RewriteRule (.*) /en/$1

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

I got the 404 not found error everytime I access the subdomains which redirected to address like: 每次访问重定向到以下地址的子域时,我都收到404 not found错误:

http://www.en.abc.com/en/index.php/en/ 

My question is, from where should I start implement it? 我的问题是,我应该从哪里开始实施它?

Thanks. 谢谢。

For me this looks like a structure problem rather than a CI problem but i'll give you some thought about it 对我来说,这看起来像是结构问题,而不是CI问题,但我会考虑一下

  1. You should think about whether you need different models and controllers per language or not. 您应该考虑每种语言是否需要不同的模型和控制器。

  2. If you need different models etc. simply create 2 different CI installations. 如果您需要不同的型号等,只需创建2个不同的CI安装即可。 For example - since you are using Apache, i give you a concrete example: Make in your document root Folder for each language a folder and point any subdomain via vhost to the appropriate directory. 例如-由于您使用的是Apache,因此我举一个具体的例子:在文档根文件夹中为每种语言创建一个文件夹,然后通过vhost将任何子域指向适当的目录。 As alternative you can use CI as a mulitple application environment take a look at this link 作为替代方案,您可以将CI用作多种应用程序环境,请查看此链接

  3. if you wish to choose the same models, controllers and views, you really have to think about your routing. 如果您希望选择相同的模型,控制器和视图,则必须考虑布线。 Do you wish the same url names for all languages or do you like language dependent urls (for this purpose you should think about a pre controller hook with a DB System behind of that to choose where the link should route to the desired controller) 您是希望所有语言使用相同的URL名称还是喜欢依赖于语言的URL(为此,您应该考虑一个预控制器钩子,该钩子后面有一个DB System,以选择链接应路由到所需控制器的位置)

  4. in your url http://www.en.abc.com/en/index.php/en/ there are too much "ens". 在您的网址http://www.en.abc.com/zh-CN/index.php/en/中 ,“ ens”过多。 In fact if you have a language prefix as subdomain you don't need "en" at all as a suffix. 实际上,如果您将语言前缀作为子域,则根本不需要后缀“ en”。 En.abc.com is the way to go. En.abc.com是必经之路。

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

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