1

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

2
  • 1
    CodeIgniter has a good documentation about routes: codeigniter.com/user_guide/general/routing.html Commented Jun 30, 2016 at 8:53
  • I suppose that you are searching product by $this->uri->segment(3) or 41. You have to change your controller/model logic and search product by slug instead searching by id. Then you can use URL without id in it. Commented Jun 30, 2016 at 13:13

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

it is still not working. main is controller and singlePage is function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.