Vasanthan.R.P
Vasanthan.R.P

Reputation: 1287

codeigniter routes remove the controller name

In my site i have many controllers like 1. admin 2. pages 3. hotels ...

My url is http://localhost/pages/page/about ---> I want it to be as http://sitename/page/about

http://localhost/admin/admin---> I want it to be as http://sitename/admin

http://localhost/hotels/display/samplehotel---> I want it to be as http://sitename/display/samplehotel

in my routes file i write as $route['pages'] = "pages/$1"; [Pages is my controller name].

But it shows an error. How to write this. Please help me

Upvotes: 0

Views: 3034

Answers (3)

Mohammad Javad Naderi
Mohammad Javad Naderi

Reputation: 506

$route['page/(:any)'] = 'pages/page/$1';

Or just:

$route['page/about'] = 'pages/page/about';

CodeIgniter URI routing documentation: http://ellislab.com/codeigniter/user-guide/general/routing.html

For admin part, I think it is better to change the name of your function from admin to index, and you don't need to set a routing rule for it.

Upvotes: 3

minboost
minboost

Reputation: 2563

$route['page/(:any)'] = "pages/page/$1";
$route['admin/(:any)'] = "admin/admin/$1";
$route['display/(:any)'] = "hotels/display/$1";

Upvotes: 0

Runish Kumar
Runish Kumar

Reputation: 194

Try writing

$route['page/about'] = 'controler_name/method_name';

if you method takes input you can write

$route['page/(:any)'] = 'controler_name/method_name/$1';

Upvotes: 1

Related Questions