简体   繁体   中英

Codeigniter URL rewrite to hide controler and method name

我当前的网址是universitytwig.com/user/userprofile/cm.cm,其中user是控制器,userprofile是方法,cm.cm是参数。我如何通过路由将此网址更改为universitytwig.com/cm.cm。 php或通过数据库路由,或通过.htaccess

Try to add

$route['cm.cm'] = 'user/userprofile/cm.cm';

to your application/config/routes.php

Or

$route['(:any)'] = 'user/userprofile/$1';

if your parameter can be different.

you can use the routes.php but if you make a rule in something like cm.cm to user/userprofile/cm.cm

$route['(:any)']= 'user/userprofile/$1';

But this is not a perfect solution it will point all the controllers of every thing after base url to user/userprofile/ you need to specify some string the CI routes will identify that this needs to be point on this controller if cm.cm is dynamic parameters not hard coded for this your url structure should be

universitytwig.com/students/cm.cm

and in routes you can now make a rule

$route['students/(:any)']= 'user/userprofile/$1';

This will work for your scenario

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