Yii framework - Change module URL
I have a module called 'admin' in my application, which is accessible at /mysite/admin. To improve the site security I want to change this URL to something more difficult to guess to the normal users and only the site admin will know.
I tried urlManager rules but couldn't get the desired result, for example:
'admin-panel'=>'admin/default/index',
'admin-panel/login'=>'admin/default/login'
But this will only work for those two URLs.
So the only thing I can think of now is to rename the actual module. The module name is referenced a lot throu开发者_运维知识库ghout the app so that it is too difficult to do. anyone have any other suggestions?
rules=>array(
'admin-panel' =>'admin',
'admin-panel/<_c:\w+>/<_a:\w+>/<id:\d+>' =>'admin/<_c>/<_a>/<id>',
'admin-panel/<_c:\w+>/<_a:\w+>' =>'admin/<_c>/<_a>',
'admin-panel/<_c:\w+>' =>'admin/<_c>',
)
But it's just alias - your admin module still will be available by /admin/ URL. Actually you must check access for users, don't try to hide your admin panel.
Take a look at URL Management (Parameterizing Routes) from the Definitive Guide. Something like this should do the job:
array(
'<_c:(admin\-panel)>/<_a>' => 'admin/default/<_a>',
)
But you're just 'renaming' your default controller in the admin module and it will still be accessible under your old URL.
try adding:
'admin-panel'=>'admin',
'admin-panel/<controller:\w+>'=>'admin/<controller>',
'admin-panel/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>',
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'module/<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>',
'module/<m:\w+>/<c:\w+>/<a:\w+>'=>'<m>/<c>/<a>',
)
),
精彩评论