dongpu3898 2013-10-09 14: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 15: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条)

报告相同问题?

悬赏问题

  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题