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.