Passing GET parameters through htaccess + Codeigniter

安稳与你 提交于 2019-12-13 06:52:26

问题


I am using CodeIgniter Framework with this .htaccess command for "nice urls".

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

All URLs, for e.g.:

  • example.com/admin/xxx/
  • passed as -> example.com/index.php?admin/xxx/ (look like CodeIgniter's ?/class/method/)

But question is: How can I pass $_GET paramaters? For Example:

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

I need use GET params od external ajax scripts (f.e.: ElFinder based on CODEIGNTER)

Thanks for advices


Edit:
I solved this problem just using POST method at Elfinder: Elfinder - Request type
But btw using $_GET params in codeigniter with mark "?" with this .htaccess, is impossible


回答1:


Have you read through the CodeIgniter documentation on URI segments?

It explains how you could pass through your action and time parameters.

For example example.com/admin/xxx/die/now would match up to the Controller

class Admin extends CI_Controller {

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

}

Alternatively as @War10ck suggested you could Use the Input class to get the required $_GET parameters. e.g.

class Admin extends CI_Controller {

    public function xxx() {

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

    }

}


来源:https://stackoverflow.com/questions/27851074/passing-get-parameters-through-htaccess-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!