【问题标题】:.htaccess Issues, Virtual Subdomains & Codeigniter.htaccess 问题、虚拟子域和 Codeigniter
【发布时间】:2011-03-30 22:04:40
【问题描述】:

基本上我的问题是这样的。我已经建立了一个接受通配符子域的系统,并将它们重写为单个 CodeIgniter 安装。有一个名为 dispatcher 的控制器,它接受它需要的参数,以及传递 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, etc.

任何帮助将不胜感激。

【问题讨论】:

    标签: apache .htaccess codeigniter httpd.conf


    【解决方案1】:

    我通过使用以下指令解决了这个问题:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-08
      • 2013-04-04
      • 1970-01-01
      • 2014-02-07
      • 2012-07-11
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多