CodeIgniter - how to remove class name in url

+3


source to share


2 answers


To map www.domain.com/services

to pages/services

, you would like:

$route['services'] = 'pages/services'

      

If you want to map www.domain.com/whatever

to pages/whatever

and anything that has multiple choices and you have multiple controllers, you should:

// create rules above this for all controllers.

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

      



That is, you need to create rules for all of yours controllers/actions

, and the last one should be a catch-all rule as above.

If you have too many controllers and want to decide this particular route, in your file routes.php

it is safe to:

$path = trim($_SERVER['PATH_INFO'], '/');
$toMap = array('services', 'something');
foreach ($toMap as $map) {
    if (strpos($path, $map) === 0) {
       $route[$map] = 'pages/'.$map;
    }
}

      

Note. Instead, $_SERVER['PATH_INFO']

you can try $_SERVER['ORIG_PATH_INFO']

or any other component that will give you the full url. Also, the above is untested, this is just an example to get you started.

CodeIgniter Routes - Remove class name from url for only one class

+2


source


try this:



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

      

+1


source







All Articles