Basically I'm trying to make a codeigniter app with localization subdomains such that if I access:
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
there would only be 1 system folder and 1 application folder:
root /system /application index.php
now i want the urls to stay put from whichever localization they 开发者_开发百科are. like:
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
how will i be able to implement this?
pardon me if my inquiry is a bit crude. but i hope someone can help me.
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...
/*
* -------------------------------------------------------------------
* 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
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
$this->config->item('region_prefix');
And then just point all of the subdomains at the same directory and localize within your app.
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.
If I recall correctly, subdomain redirects are documented somewhere on apache.org, and you'll find more info than I've provided on google
精彩评论