私はこのURLを持っています:
http://mysite.com/pages/index?slug=how-does-it-work
そのURLを次のように変更したい:
http://mysite.com/how-does-it-work
ご覧のとおり、URL で削除されていますpage
。index
ここのページはコントローラーであり、インデックスはコントローラーのアクションです。これは私のページコントローラーのコードです:
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 出力に変換する方法がわかりません。私がしたことを投稿しなかったのはそのためです。
あなたの助けは大歓迎です! ありがとう!:)