Search code examples
phpcodeigniterurl-routing

Codeigniter URI Parameter Mapping


I have a site that I want to pass directly to the controller method without going through the class in codeigniter.

https://website.com/product_number instead of https://website.com/index/product_number

I want that to go directly to my main controller method.

config/routes.php

$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

controllers/Welcome.php

function index($product_number)
{
  //process $product_number output
}

Would this be possible in codiegniter?


Solution

  • Open config/routes.php then add this line to it

    $route['(.+)'] = 'welcome/index/$1'; I hope this helps your situation.