iammrharuna
iammrharuna

Reputation: 31

Remove controller name from codeigniter 2 url path

I am having trouble removing the controller name from my url path on my localhost.

i have this url - localhost:8888/localhost/site_name/

i have been able to remove index.php from the url using my htaccess similar to http://codeigniter.com/wiki/mod_rewrite so that:

localhost:8888/localhost/site_name/index.php/controller_name

is now:

localhost:8888/localhost/site_name/controller_name/

but i can't remove the controller name from the path so that:

localhost:8888/localhost/site_name/controller_name/function_name/

becomes:

localhost:8888/localhost/site_name/function_name/

I am using only one controller, and i have added:

$route['^(function_name1|function_name2|function_name3)(/:any)?$'] = 'controller_name/$0'; 

$route['^(?!ezstore|ezsell|login).*'] = "home/$0"; /*similar variation i tried*/

and other variations to my routes file but it does not have any effect. i also tried using the _remap function but that does not help in this case.

Any help will be appreciated! Thanks

Upvotes: 1

Views: 2042

Answers (1)

Hailwood
Hailwood

Reputation: 92581

You can use a wildcard route,

$route['(:any)'] = "controller_name/$1";

Then when if you go to http://localhost/function_one/param1

it will call the controller controller_name the function function_once and pass param1 as the first parameter.


nb: I must point out, using only one controller for an entire site does raise warning bells for me, you may want to get your code design checked out, but that's just me.

Upvotes: 1

Related Questions