Code Igniter Redirect Issues with GET parameters Code Igniter Redirect Issues with GET parameters codeigniter codeigniter

Code Igniter Redirect Issues with GET parameters


With that rewrite rule RewriteRule ^(.*)$ /index.php?/$1, here are some examples of rewrites that are occuring:

http://www.mysite.com =>
http://www.mysite.com/index.php?/ (actually, this might not be being rewritten at all)

http://www.mysite.com/mycontroller/mymethod/?ref=p&t2=455 =>
http://www.mysite.com/index.php?/mycontroller/mymethod/?ref=p&t2=455

http://www.mysite.com/?ref=p&ts=455 =>
http://www.mysite.com/index.php?/?ref=p&t2=455

The first one will work whether it is being rewritten or not. CodeIgniter is processing either an empty query string (which is easy) or a query string of simply "/".

The second one (which also works) is being rewritten, but CodeIgniter is able to process its query string, which is /mycontroller/mymethod/?ref=p&t2=455. CI turns that into an array of segments as

[0] => mycontroller[1] => mymethod[2] => ?ref=p&t2=455

Array index 2 ultimately gets ignored by anything you're doing.

The third one (which does not work is being rewritten, and CodeIgniter can't process its query string at all. Its query string is rewritten to: /?ref=p&t2=455. That makes for an array of segments that looks like this:

[0] => ?ref=p&t2=455

which doesn't match any controller on your site.

Probably, you'll fix the whole thing by modifying the RewriteRule from
RewriteRule ^(.*)$ /index.php?/$1 to
RewriteRule ^(.*)$ /index.php/$1
at which point you'd probably want to change the uri_protocol config back to PATH_INFO.


It seems to be a limitation in the way CodeIgniter is designed, not as a result of your routing and/or .htaccess. Someone filed a bug report here. However, instead of using this and adding your mymethod code into your index method of your default controller, you could use the _remap() function like so:

function _remap($method){    if ($method == 'index' && count($_GET) > 0)    {        $this->mymethod();    }    else    {        $this->index();    }}


With the following configuration it works fine for me. http://www.site.com/?x=y gets routed to the index method of the default controller.

.htaccess

RewriteEngine onRewriteCond $1 !^(index\.php)RewriteRule ^(.*)$ index.php/$1 [L]

system/application/config/config.php

$config['base_url'] = "http://www.site.com/";$config['index_page'] = "";$config['uri_protocol'] = "PATH_INFO";$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';

Remember to add ? to the list of permitted characters in the URL. Perhaps this is causing a problem. I just tried this setup with a clean installation of CodeIgniter and it worked fine. These were the only changes I needed to do.