I am using one controller. How can I remove or hide the controller name on my URL using routes? I already set my .htaccess to remove my index.php. I\'ve tried lots of code from
You can define a custom route in config/routes.php - for example:
$route['about'] = 'name_controller/about';
Then, http://example.com/about goes to http://example.com/name_controller/about
See more http://ellislab.com/codeigniter/user-guide/general/routing.html
Simple approach when i use CI:
Example Controller:
<?php
class Haha extends CI_Controller
{
public function check()
{
$this->load->view('path/to/check/view');
}
public function choke()
{
$this->load->view('path/to/choke/view');
}
}
Example routes:
//same name with C method
$route['check'] = 'haha/check';
$route['choke/(:any)'] = 'haha/choke';
//or custom route name
$route['squirrel'] = 'haha/check';
$route['woohoo/(:any)'] = 'haha/choke';
My htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
Access the uri:
http://yoursite.com/check
http://yoursite.com/choke/whatever
//or
http://yoursite.com/squirrel
http://yoursite.com/woohoo/whatever
Addition: Here is complete routes from my old project using CI, maybe you can get something.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'sitehome';
$route['page'] = 'sitehome/page';
$route['page/who-we-are'] = 'site/whoweare';
$route['page/why-use-us'] = 'site/whyus';
$route['page/about-us'] = 'site/about';
$route['page/contact-us'] = 'site/contact';
$route['page/news'] = 'site/news/news';
$route['page/topics'] = 'site/topic';
$route['page/polls'] = 'site/polls';
$route['page/results'] = 'site/result';
$route['agent/detail/(:any)'] = 'site/agentdetail';
$route['register'] = 'site/register';
$route['login'] = 'site/login';
$route['user/home'] = 'usermain';
$route['user/edit-account'] = 'user/editaccount';
$route['user/retire'] = 'user/retired';
$route['user/business/data'] = 'user/business';
$route['user/business/topic/create'] = 'user/topic/topiccreate';
$route['user/business/topic/view'] = 'user/topic/topicview';
$route['user/business/topic/edit/(:num)'] = 'user/topic/topicedit';
$route['user/inbox'] = 'user/inbox';
$route['user/message/read/(:any)'] = 'user/readmessage';
$route['user/provider/list'] = 'user/providerlist';
$route['user/provider/send-message/(:any)'] = 'user/providerlist/sendmessage';
$route['user/notification'] = 'user/notified';
$route['user/inquiry'] = 'user/inquiry';
//testing purpose
$route['percobaan'] = 'coba/percobaan';
$route['poll'] = 'site/polls/retrievePoll';
//serve response
$route['response/single-poll'] = 'api/ResponseData/serveHomePoll';
$route['response/multi-poll'] = 'api/ResponseData/servePoll';
$route['404_override'] = 'notFound';
$route['translate_uri_dashes'] = FALSE;
/* End of file routes.php */
/* Location: ./application/config/routes.php */
Notes :
http://example.com/business/
will fail or not exist.
Good luck.