1

I need help to rewrite url and remove controller as well as function name from url given url is my current uel.

URL :http://localhost/example/Loadercontrol/detail/200

I want this type of url

URL : http://localhost/example/name (replace id with name).

I already try rewrite url as well as

$route['example'] = 'localhost/example/Loadercontrol/detail';  

but it's not working. I've really tried to fix the issue. Please help me.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sg web
  • 11
  • 1
  • Hey, I think you need to use ```slug``` for this. But as you don't want the controller name also, then you need to create the routes from database somehow in ```routes.php``` – kishor10d Dec 19 '16 at 07:16
  • if you don't want to write the routes from database then you can do this. ```$routes["(:any)"] = "Loadercontrol/(:any');```. But it will harm to your 404 page redirection. – kishor10d Dec 19 '16 at 07:18
  • search the slug like this http://stackoverflow.com/questions/3305786/using-slugs-in-codeigniter hope it will help you. – NomanJaved Dec 19 '16 at 07:27
  • This link will help you http://stackoverflow.com/questions/7094302/codeigniter-is-it-possible-to-remove-the-controller-function-from-the-url-usi?rq=1 – kishor10d Dec 19 '16 at 07:28
  • still i fetch same issue i alredy try in routes.php and $route['example/(:num)'] = 'example/Loadercontrol/detail/$1'; – sg web Dec 19 '16 at 07:30
  • i already try http://stackoverflow.com/questions/7094302/codeigniter-is-it-possible-to-remove-the-controller-function-from-the-url-usi?rq=1 this linkk but i can't fix issue – sg web Dec 19 '16 at 08:25
  • just do as Hikmat suggested below, but replace :num by :any – B. Assem Dec 21 '16 at 23:23

1 Answers1

1

Try like this..

$route['example/(:num)'] = 'example/Loadercontrol/detail/$1';

For details see more here...https://www.codeigniter.com/userguide3/general/routing.html#wildcards

Wildcards are actually aliases for regular expressions, with :any being translated to [^/]+ and :num to [0-9]+, respectively.

Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19