Tuesday, 15 July 2014

php - how to rewrite url in Yii? -



php - how to rewrite url in Yii? -

i have action named contact in site controller, when open in browser, url displayed as: mysite.com/index.php/site/contact, want alter view name of action, should mysite.com/contact.php, how ?

to remove index.php url you'll need add together 'showscriptname' => false components urlmanager array in /protected/config/main.php file:

// application components 'components'=>array( ... 'urlmanager'=>array( 'urlformat'=>'path', 'showscriptname'=>false, 'rules'=>array( ... ), ... ), ... ),

that create route contant page mysite.com/site/contact. in order remove /site you'd need edit rules array, may work;

// application components 'components'=>array( ... 'urlmanager'=>array( 'urlformat'=>'path', 'showscriptname'=>false, 'rules'=>array( ... '<action:\w+>.php'=>'site/<action>', ... ), ... ), ... ),

this mean url mysite.com/contact.php render site/contact route.

edit

in reply question 'no want render mysite.com/one, 1 string id':

you've got careful such short url rules, broad rules picked other paths , reroute user when don't want them redirected. however, redirect mysite/one mysite/mycontroller/myaction?id=one utilize '<id:\w+>'=>'mycontroller/myaction'

but, said, careful, reroute everything 1 word path. illustration take scenario:

you have controller named user you want navigate index action of user controller (route user/index) you navigate mysite.com/user (which render mysite.com/user/index)

this instead redirect user mysite/mycontroller/myaction?id=user

php yii url-routing

No comments:

Post a Comment