dongpu3898 2013-10-09 06:55 采纳率: 100%
浏览 45
已采纳

Yii使用重定向自动更正当前网址

THere's no secret, that Yii thinks those are equal addresses:

And config:

...
'urlFormat'=>'path',
'urlSuffix'=>'.html',
'showScriptName'=>false,
...

What is the best way to make Yii correct current URI if it has no ".html"?

  • 写回答

2条回答 默认 最新

  • douqulv6059 2013-10-09 07:08
    关注

    Well, you should simply try this :

    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        '<controller:\w+>/<action:\w+>\.html'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
    

    And to handle redirect, add this in your action (or in beforeAction or a filter) :

    if (substr(Yii::app()->request->url, -5)!=='.html')
    {
        $this->redirect(array($this->action->id, /* add your action params here */));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部