1

基本上我的问题是这个。我已经建立了一个接受通配符子域的系统,并将它们重写为单个 CodeIgniter 安装。有一个称为调度程序的控制器,它接受它需要的参数,以及传递 URL 中使用的子域。

我的问题是:我需要创建符合 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 ”的 URL,但不适用于“ http://example.ev-apps.com/app/method ”。似乎优先级都是错误的,但理想情况下,我想要一个适用于任意数量段的解决方案,例如:“ http://example.ev-apps.com/app/method/1/2/3/4 /5/6/7/8/9

任何帮助将不胜感激。

4

1 回答 1

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] : '');

感谢阅读,如果你这样做了!

于 2010-08-17T12:39:34.987 回答