【问题标题】:Passing GET parameters through htaccess + Codeigniter通过 htaccess + Codeigniter 传递 GET 参数
【发布时间】:2015-01-08 22:57:12
【问题描述】:

我正在将 CodeIgniter 框架与 .htaccess 命令一起用于“漂亮的 url”。

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php?$1 [L]

所有网址,例如:

  • example.com/admin/xxx/
  • 传递为 -> example.com/index.php?admin/xxx/(看起来像 CodeIgniter 的 ?/class/method/

但问题是:我怎样才能传递$_GET 参数?例如:

  • example.com/admin/xxx/?action=die&time=now

我需要使用 GET 参数和外部 ajax 脚本(例如:基于 CODEIGNTER 的 ElFinder)

感谢您的建议


编辑:
我在 Elfinder 使用 POST 方法解决了这个问题: Elfinder - Request type
但是顺便说一句,在带有标记“?”的代码点火器中使用 $_GET 参数。有了这个.htaccess,是不可能的

【问题讨论】:

  • 检查 CodeIgniter 的 Input class 和配置文件中的 $config['allow_get_array] 设置。

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

您是否阅读了URI segments 上的 CodeIgniter 文档?

它解释了你如何可以传递你的actiontime 参数。

例如,example.com/admin/xxx/die/now 将匹配 Controller

class Admin extends CI_Controller {

    public function xxx($action, $time) {
        // Stuff
    }

}

或者,正如@War10ck 建议的那样,您可以使用Input 类来获取所需的$_GET 参数。例如

class Admin extends CI_Controller {

    public function xxx() {

        $action = $this->input->get('action');
        $time = $this->input->get('time');

    }

}

【讨论】:

  • 是的,访问 GET 参数是可以的,但 htaccess 重定向被提前触发并将我重定向到没有 $_GET 参数的页面。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-25
相关资源
最近更新 更多