Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case Insensitive Routing in CodeIgniter

I've written this in the CodeIgniter's routers.

$route['companyname'] = "/profile/1";

This is working fine but when I type "CompanyName" into the URL then it doesn't work. This is because upper case characters.

I want to make this routing case insensitive. Please suggest the best way.

like image 363
Tuhin Avatar asked Nov 27 '22 14:11

Tuhin


2 Answers

Just add expression "(?i)"
Here example:
$route['(?i)companyname'] = "/profile/1";

like image 130
Andri Kurniawan Avatar answered Dec 24 '22 12:12

Andri Kurniawan


If you want case-insensitive routing for all routes, you just need to extend CI_Router class, then modify _parse_routes() method like this:

public function _parse_routes()
{
    foreach ($this->uri->segments as &$segment)
    {
        $segment = strtolower($segment);
    }

    return parent::_parse_routes();
}

It will be cleaner than editing the CI_URI class itself. :)

like image 30
Kevin Putrajaya Avatar answered Dec 24 '22 11:12

Kevin Putrajaya