You can prepare your config like this:
$config['base_url'] = 'your_base_url';
$config['index_page'] = ''; // empty string
$config['enable_query_strings'] = FALSE; // keep it to default FALSE, you can use it even without enabling it here
and your .htaccess like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I think that is it, now you can use both segments and query_strings like this:
http://localhost/codeigniter/?c=welcome&m=index
http://localhost/codeigniter/welcome/index
http://localhost/codeigniter/index.php/welcome/index
http://localhost/codeigniter/index.php?c=welcome&m=index
http://localhost/codeigniter/index.php/?c=welcome&m=index
I've already tested both in my environment and it works just fine.
Edit: in my codeigniter template i've extended my core router and slightly changed the _set_routing() method like this:
Of course it is a bad practice to change the core system, so you need to extend the core router file and create MY_Router.php under application/core and make it extend CI_Router like this:
class MY_Router extends CI_Router
{
protected function _set_routing()
{
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
$_c = trim($this->config->item('controller_trigger'));
if ( ! empty($_GET[$_c]))
{
$this->uri->filter_uri($_GET[$_c]);
$this->set_class($_GET[$_c]);
$_f = trim($this->config->item('function_trigger'));
if ( ! empty($_GET[$_f]))
{
$this->uri->filter_uri($_GET[$_f]);
$this->set_method($_GET[$_f]);
}
$this->uri->rsegments = array(
1 => $this->class,
2 => $this->method
);
}
else
{
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}
}
Now you you have the best of both worlds, you will keep your segments with its goodies untouched but will always look for get c=&m=, i hope its clear enough.
We kept everything to default and made it check for a get request with c and m pretty like what enable_query_strings does but without enabling it and messing anything up to keep working with segments as it is..
index.phpand new withoutindex.php?$config['allow_get_array'] = TRUE; $config['enable_query_strings'] = TRUE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd';Also change$config['uri_protocol']= 'AUTO';To Other value and PATH_INFO is take effect but still i am not getting the result. The config not allow to work with both type of url at same time. Either it allows old url or new url.