简体   繁体   中英

How to rewrite URL with Codeigniter?

In Codeigniter how to rewrite URL?

I already tried to change the route like this :

$route['backend/user/profile/(:num)/'] = 'backend/user/profile/$1/$2';

But still nothing could change.

I have url : http://pa.ig/backend/user/profile/204/disabled
Url Expected : http://pa.ig/backend/user/profile/204

Please help me to fix this. Thank you.

如果最后一个参数是字符串,则可以使用(:any)

$route['backend/user/profile/(:num)/(:any)']  = 'backend/user/profile/$1';

if the second parameter is optional, you can try this

in your routes :

$route['backend/user/profile/(:num)'] = 'backend/user/profile/$1';
$route['backend/user/profile/(:num)/(:string)'] = 'backend/user/profile/$1/$2';

and in your controller , give default value for the second parameter of your function

public function profile( $id , $stat = 'disabled' ) {
  // your code ..
}

so, if the second parameter ( $stat ) ommitted in URL, it will get disabled value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM