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

非 Y 不嫁゛ 提交于 2019-11-29 13:41:19

You can set your a route for each url:

In your config/routes.php file, just set each page like this:

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

This might help you to define a Default Controller for your CodeIgniter project.

https://codeigniter.com/user_guide/general/controllers.html#defining-a-default-controller

For instance, in your case, open your application/config/routes.php file and set this variable:

$route['default_controller'] = 'site_controller';

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/

Tom Millard

try using the routes file to re-map url's

http://ellislab.com/codeigniter/user_guide/general/routing.html

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 :)

Lokanath

This helped for me. In "routes.php" I added this:

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!