Php Yii清理URL

Php Yii清理URL,php,yii,Php,Yii,我有这个网址: http://mysite.com/pages/index?slug=how-does-it-work 我想将该url更改为如下所示: http://mysite.com/how-does-it-work 如您所见,页面和索引已在url中删除。 这里的页面是控制器,而索引是控制器的操作。 这是我的页面控制器上的代码: public function actionIndex($slug) { if(!empty($slug)) { $pagesInfo =

我有这个网址:

http://mysite.com/pages/index?slug=how-does-it-work
我想将该url更改为如下所示:

http://mysite.com/how-does-it-work
如您所见,
页面
索引
已在url中删除。 这里的页面是控制器,而索引是控制器的操作。 这是我的页面控制器上的代码:

public function actionIndex($slug)
{
   if(!empty($slug))
   {
    $pagesInfo = Pages::model()->find(array("condition"=>"slug='$slug'"));
    $isAdmin = 0;
    if(isset(Yii::app()->user->idUser)){
       $isAdmin = Users::model()->findByPk(Yii::app()->user->idUser)->isAdmin;
    }

    if($pagesInfo !== null){
      $this->render('index',array(
        'pagesInfo'=>$pagesInfo,
        'isAdmin'=>$isAdmin,
       ));
    }else{
       throw new CHttpException(404,'Page cannot be found');
    }
   }
}
这也是我的
.htaccess

IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
老实说,我不知道如何将该URL转换为预期的URL输出。我知道这就是为什么我没有发布我所做的事情


非常感谢您的帮助!谢谢!:)

您是否已经将项目的config/main.php中的“urlFormat”更改为“path”


您想如何调用此操作?

您只需修改您的urlManager配置,例如:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        '<slug>'=>'page/index',

        // ... other rules
    ),
),
'urlManager'=>数组(
“urlFormat'=>“路径”,
'showScriptName'=>false,
'规则'=>数组(
''=>'页面/索引',
//……其他规则
),
),

Elson,当您访问第二个URL时会发生什么?修改后,第一个仍然有效吗?