これは、url の言語コードに似ています。
私のソリューションを使用すると、任意のセグメントを uri に配置して、CI に非表示にすることができます。
http://site.com/page.htmlはhttp://site.com/canada/page.htmlと等しくなり、その逆も同様です。
set_country_uri.php
//App location
$ci_directory = '/ci/';
//countries
$countries = array('canada','france');
//default country
$country = 'canada';
foreach( $countries as $c )
{
if(strpos($_SERVER['REQUEST_URI'], $ci_directory.$c)===0)
{
//Store country founded
$country = $c;
//Delete country from URI, codeigniter will don't know is exists !
$_SERVER['REQUEST_URI'] = substr_replace($_SERVER['REQUEST_URI'], '', strpos($_SERVER['REQUEST_URI'], '/'.$c)+1, strlen($c)+1);
break;
}
}
//Add the country in URI, for site_url() function
$assign_to_config['index_page'] = $country."/";
//store country founded, to be able access it in your app
define('COUNTRY', $country);
index.php
<?php
require('set_country_uri.php');
//ci code ...
したがって、CIコードではCOUNTRY
定数を使用して、使用されているものを確認してください。また、URI の国を考慮せずにコードをルーティングのようにします。