2011-05-06 30 views
6

基本上我試圖與本土化子域名笨的應用程序,例如,如果我訪問:單個笨應用通配符子域

ca.site.com - >它將運行在同一個系統,但顯示加拿大內容。 us.site.com - >仍然運行相同的系統,但顯示美國內容。

再加上如果我訪問www.site.com,它會使用ip2country自動獲得正確的定位,並會被重定向一樣,如果來自英國,再導向到uk.site.com

只會有1個系統文件夾和1個應用程序文件夾:

根 /系統 /應用 的index.php

現在我想的URL遠離他們是哪個本地化投入。像:

uk.site.com/profile/1將訪問配置文件控制 ca.site.com/profile/3還將訪問同一個控制器uk.site.com使用

我將如何能夠實現這一點?

對不起,如果我的詢問有點粗俗。但我希望有人能幫助我。

回答

2

更多信息也許有很多方法可以做到這一點...而是一個我能想到的把我的頭頂部放東西在預加載自定義配置值確定,的確是這樣的index.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]; 

,然後在config.php文件

global $region_prefix_var; 
$config['base_url'] = $region_prefix_var[0].".site.com/"; 

...或者您可以根據$ _SERVER ['HTTP_HOST']值覆蓋$ assign_to_config數組中的index.php文件中的base_url。然後,在任何其他控制器或任何你可以立足的東西掉

$this->config->item('region_prefix'); 

然後再移動所有的子域在同一目錄下,你的應用程序中定位。

0

你必須找到一種方法來允許動態子域重定向(顯然它可能帶有一點點.htaccess mod_rewrite魔術),然後創建一個主控制器,並且索引方法的第一個參數是語言,然後子域重定向從(.*).site.com/(.*) = site.com/$1/$2,這應該工作,但它不是遵循傳統的CodeIgniter的MVC方法,而更像是一種黑客而不是正確的方式來做到這一點,我相信別人會知道更多的語義方式這個工作。

如果我沒有記錯,子域名重定向某處記錄在apache.org,你會找到一個比我提供的google