这不是秘密,Yii认为那些是平等的地址:
并配置:
...
'urlFormat'=>'path',
'urlSuffix'=>'.html',
'showScriptName'=>false,
...
如果Yii没有“.html”,那么使Yii更正当前URI的最佳方法是什么?
答案 0 :(得分:1)
嗯,你应该试试这个:
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<action:\w+>\.html'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
要处理重定向,请在您的操作中(或在beforeAction或过滤器中)添加:
if (substr(Yii::app()->request->url, -5)!=='.html')
{
$this->redirect(array($this->action->id, /* add your action params here */));
}
答案 1 :(得分:0)
这是我最好的解决方案:
class Controller extends CController {
public function beforeAction($a) {
if(strlen(Yii::app()->request->url)>1)
if(!$strpos = strpos(Yii::app()->request->url,'.html')) {
//html not found... need to correect
if(!($strpos = strpos(Yii::app()->request->url,'?'))) {
$this->redirect(Yii::app()->request->url.".html", true, 301);
} else {
$newUrl = substr(Yii::app()->request->url,0,$strpos).".html".substr(Yii::app()->request->url,$strpos);
$this->redirect($newUrl, true, 301);
}
};
return true;
}
}