llbbl - 08 December 2007 06:26 PM
RewriteRule ^(.*)$ index.php?/$1 [L]
While the above works, and fixes the issue in most cases, I came across a problem where if I wanted to allow URL parameters (enabling query strings), the $_GET array was not being populated correctly because something like this:
http://mysite.com/controller/action/?var=val&var2=val2
On Dreamhost (with PHP as CGI) using the RewriteRule above turns into:
http://mysite.com/index.php?/controller/action/?var=val&var2=val2
Which causes CodeIgniter (due to the extra ’?’) to have the $_GET array not be populated as expected (with var,var2 as keys and val,val2 as values).
The solution I came up (for us with Dreamhost, running PHP 5.2+ as CGI) was to repopulate the $_GET array using the REQUEST_URI by creating an extension of of the CI_Input class. The solution is to create a MY_Input.php (as explained by a previous poster) under application/libraries:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input extends CI_Input {
function __construct(){ //Or MY_Input()
//get the URL query string from the REQUEST_URI
$get_string = array_pop( explode('?',$_SERVER['REQUEST_URI'],2) );
//parse the pairs of parameters
$pairs_array = explode('&',$get_string);
/*
adding these values to the GET array before sending it to the
Core Input class.
*/
foreach($pairs_array as $pair){
list($key,$value) = explode('=',$pair);
$_GET[$key] = $value;
}
//continue as normal
parent::CI_Input();
}
}
You will still have to set the following in your config file (as explained previously in this thread):
$config['uri_protocol'] = "AUTO";
$config['enable_query_strings'] = TRUE;
I’m sure someone can write better code than I can. I just wanted to help other CI deployments, since I didn’t find a solution to this issue.