How to remove controller name from url making it clean in codeigniter

后端 未结 9 1295
余生分开走
余生分开走 2020-12-20 16:50

I have the following url..

http://localhost/ci/site_controller/home

I want to remove site_controller controller

相关标签:
9条回答
  • 2020-12-20 17:18

    I just found the solution in this link, it works for me: http://ellislab.com/forums/viewthread/148531/

    $route['^(page1|page2|page3|page4)(/:any)?$'] = "YOURCONTROLLERNAME/$0";
    

    Hope it helps you :)

    0 讨论(0)
  • 2020-12-20 17:19

    Drop the 'ci' from your routes. That is your project name and is never required. Routes always start on the controller level:

    $route['home'] = "site_controller/home";
    

    Will work. However, more importantly.. are you sure your design is correct? Why not just let home be a controller? Create a /application/controllers/home.php and you'll be able to access it's index() function with http://localhost/ci/home.

    You're complicating things. No need for routes at all.

    0 讨论(0)
  • 2020-12-20 17:22

    assuming you currently have your url http://localhost/ci/site_controller/home you can just write an explicit route like below to your /application/config/routes.php

    $route['ci/home'] = 'site_controller/home';
    

    or

    $route['ci/home'] = 'ci/site_controller/home';
    

    if your controller is namespaced to /application/controllers/ci/

    0 讨论(0)
提交回复
热议问题