2010-08-17 80 views
1

基本上我的問題是這樣的。我建立了一個接受通配符子域的系統,並將它們重寫爲單個CodeIgniter安裝。有一個名爲dispatcher的控制器,它接受它所需的參數,並傳遞URL中使用的子域名。.htaccess問題,虛擬子域名和Codeigniter

我的問題是這樣的:我需要創建符合CodeIgniter的URL結構的RewriteRules。目前,我有這樣的:

RewriteEngine On 

# Extract the subdomain part of domain.com 
RewriteCond %{HTTP_HOST} ^([^\.]+)\.ev-apps\.com$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

# Check that the subdomain part is not www and ftp and mail 
RewriteCond %1 !^(www|ftp|mail)$ [NC] 

# Redirect all requests to a php script passing as argument the subdomain 
RewriteRule ^/(.*)/(.*)$ /dispatcher/run_app/$1/$2/%1 [L,QSA] # First is app name, then site, then action 
RewriteRule ^/(.*)/(.*)/(.*)$ /dispatcher/run_app/$1/$2/$3/%1 [L,QSA] # First is app name, then site, then action, then any passed data. 

它工作正常的遵循此格式「http://example.ev-apps.com/app/method/1」的網址,而不是「http://example.ev-apps.com/app/method」。這似乎優先是完全錯誤的,但最好我想一個解決方案,適用於任何數量的段的工作,比如:「http://example.ev-apps.com/app/method/1/2/3/4/5/6/7/8/9

任何幫助,將不勝感激

回答

2

我解決了這個問題使用以下指令:

RewriteRule ^(.*)$ /dispatcher/run_app/%1/$1 [L,QSA] 

然後在我的調度員行動使用下面的代碼:

$args = func_get_args(); 

$site_subdomain = $args[0]; 
$app_name = $args[1]; 
$action = $args[2]; 
$input = (isset($args[3]) ? $args[3] : ''); 

感謝您的閱讀,如果你做到了!