Basically I'm trying to make a codeigniter app with localization subdomains such that if I access:
基本上我想做一个带有本地化子域的codeigniter应用如果我访问:
ca.site.com -> it would run the same system but shows canadian content. us.site.com -> still runs the same system but shows american content.
它会运行相同的系统,但是会显示加拿大的内容。网站->仍然运行相同的系统,但是显示了美国的内容。
plus if i access www.site.com, it would automatically get the proper localization using ip2country and would get redirected like if from uk, redir to uk.site.com
另外,如果我访问www.site.com,它会自动地使用ip2country获得适当的本地化,并且会被重定向,比如从英国,再重定向到uk.site.com
there would only be 1 system folder and 1 application folder:
只有一个系统文件夹和一个应用程序文件夹:
root /system /application index.php
根/系统/ index . php应用程序
now i want the urls to stay put from whichever localization they are. like:
现在我想让url保持不变不管它们是什么本地化。如:
uk.site.com/profile/1 will access a profile controller ca.site.com/profile/3 will also access the same controller uk.site.com uses
uk.site.com/profile/1将访问一个概要控制器ca.site.com/profile/3也将访问uk.site.com使用的相同的控制器
how will i be able to implement this?
我怎样才能实现它呢?
pardon me if my inquiry is a bit crude. but i hope someone can help me.
如果我的询问有点粗鲁,请原谅。但我希望有人能帮助我。
2 个解决方案
#1
2
There are probably a lot of ways to do this... but one that I can think of off the top of my head is to put something in the index.php file where the preloaded custom config values are established that does something like this...
可能有很多方法可以做到这一点……但是我能想到的是把一些东西放到索引中。在php文件中,建立了预加载的自定义配置值,并执行如下操作……
/*
* -------------------------------------------------------------------
* CUSTOM CONFIG VALUES
* -------------------------------------------------------------------
*
* The $assign_to_config array below will be passed dynamically to the
* config class when initialized. This allows you to set custom config
* items or override any default config values found in the config.php file.
* This can be handy as it permits you to share one application between
* multiple front controller files, with each file containing different
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
*
*/
$region_prefix_var = explode('.', $_SERVER['HTTP_HOST']);
$assign_to_config['region_prefix'] = $region_prefix_var[0];
and then in your config.php file
然后在配置中。php文件
global $region_prefix_var;
$config['base_url'] = $region_prefix_var[0].".site.com/";
...or you could just override the base_url in the index.php file in the $assign_to_config array based on the $_SERVER['HTTP_HOST'] value. Then in any other controllers or whatever you can base things off of
…或者你可以重写索引中的base_url。$assign_to_config数组中的php文件基于$_SERVER['HTTP_HOST']值。然后在任何其他的控制器中
$this->config->item('region_prefix');
And then just point all of the subdomains at the same directory and localize within your app.
然后将所有子域指向同一个目录并在应用程序中本地化。
#2
0
You'd have to find a way to allow dynamic subdomain redirects (apparently it's possible with a little .htaccess mod_rewrite magic), then make a master controller, with the first paramater on the index method being the language, then have the subdomain redirect go from (.*).site.com/(.*)
= site.com/$1/$2
, this should work, but it's not following the traditional MVC approach of CodeIgniter and is more of a hack than a proper way to do it, I'm sure someone else will know a more semantic way to work this.
你必须找到一个方法来允许动态子域名重定向(显然有可能一点。htaccess mod_rewrite魔法),然后做一个主控制器,与第一个参数指数法的语言,然后有子域名重定向从(*).site.com/。(. *)= site.com/ $ 1 / 2美元,这应该工作,但它不是传统的MVC方法后CodeIgniter,更多的是一种黑客比一个适当的方法,我相信其他人会知道一个更语义化的方法。
If I recall correctly, subdomain redirects are documented somewhere on apache.org, and you'll find more info than I've provided on google
如果我没记错的话,子域重定向在apache.org上有记录,你会发现比我在谷歌上提供的更多的信息
#1
2
There are probably a lot of ways to do this... but one that I can think of off the top of my head is to put something in the index.php file where the preloaded custom config values are established that does something like this...
可能有很多方法可以做到这一点……但是我能想到的是把一些东西放到索引中。在php文件中,建立了预加载的自定义配置值,并执行如下操作……
/*
* -------------------------------------------------------------------
* CUSTOM CONFIG VALUES
* -------------------------------------------------------------------
*
* The $assign_to_config array below will be passed dynamically to the
* config class when initialized. This allows you to set custom config
* items or override any default config values found in the config.php file.
* This can be handy as it permits you to share one application between
* multiple front controller files, with each file containing different
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
*
*/
$region_prefix_var = explode('.', $_SERVER['HTTP_HOST']);
$assign_to_config['region_prefix'] = $region_prefix_var[0];
and then in your config.php file
然后在配置中。php文件
global $region_prefix_var;
$config['base_url'] = $region_prefix_var[0].".site.com/";
...or you could just override the base_url in the index.php file in the $assign_to_config array based on the $_SERVER['HTTP_HOST'] value. Then in any other controllers or whatever you can base things off of
…或者你可以重写索引中的base_url。$assign_to_config数组中的php文件基于$_SERVER['HTTP_HOST']值。然后在任何其他的控制器中
$this->config->item('region_prefix');
And then just point all of the subdomains at the same directory and localize within your app.
然后将所有子域指向同一个目录并在应用程序中本地化。
#2
0
You'd have to find a way to allow dynamic subdomain redirects (apparently it's possible with a little .htaccess mod_rewrite magic), then make a master controller, with the first paramater on the index method being the language, then have the subdomain redirect go from (.*).site.com/(.*)
= site.com/$1/$2
, this should work, but it's not following the traditional MVC approach of CodeIgniter and is more of a hack than a proper way to do it, I'm sure someone else will know a more semantic way to work this.
你必须找到一个方法来允许动态子域名重定向(显然有可能一点。htaccess mod_rewrite魔法),然后做一个主控制器,与第一个参数指数法的语言,然后有子域名重定向从(*).site.com/。(. *)= site.com/ $ 1 / 2美元,这应该工作,但它不是传统的MVC方法后CodeIgniter,更多的是一种黑客比一个适当的方法,我相信其他人会知道一个更语义化的方法。
If I recall correctly, subdomain redirects are documented somewhere on apache.org, and you'll find more info than I've provided on google
如果我没记错的话,子域重定向在apache.org上有记录,你会发现比我在谷歌上提供的更多的信息