Hide Codeigniter controller name from URL with mul

2019-05-18 18:32发布

I'm using the following code in my routes.php to hide the controller name from the URL structure:

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

It works great, but my problem is this: When I want to access another controller, it seems to treat it as a function of the hidden controller.

So for example. I have

http://mysite.com/controller1/somefunction

which turns into:

http://mysite.com/somefunction

What if I want to access:

http://mysite.com/jsonfunction/anotherfunction/

How can I access the other controller while keeping the other one hidden? I really don't want visitors seeing http://mysite.com/maincontroller/ that's just redundant!

1条回答
Luminary・发光体
2楼-- · 2019-05-18 18:34

You are going to have to define your routes more specific I am afraid. You can still use:

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

But it will probably go to the button of your list of routes.

if you want other routes to be added that overrule that one you'll have to place them on top. For example like this:

$route['login'] = "auth/login";
$route['varY'] = "controllerX/varY";
$route['varY/(:any)'] = "controllerX/varY/$1";
$route['foobar'] = "controller/method";
$route['(:any)'] = "auth/$1";

See this document for more info and future reference: http://codeigniter.com/user_guide/general/routing.html

查看更多
登录 后发表回答