remove controller and function name from url codei

2019-07-29 05:28发布

问题:

i am currently coding in codeigniter and i want to remove the controller and function name from url so that only product slug is displayed in url.

currently my url is like
www.example.com/main/singlePage/41/product-slug

I want the url to be like
www.example.com/product-slug

回答1:

We can use routes for that, In your application/config/routes.php.

See the example,

$route['{any}']  = 'pages/slug_on_the_fly'

Ref: https://codeigniter.com/user_guide/general/routing.html



回答2:

To do this create a "catch all" route $route['{any}'] = 'controller/function' and in this function of the controller get the slug $slug = $this->uri->uri_string() and decide what to do based on it.