私はこれで立ち往生しています...
私のローカル マシン (IIS 7.5 with ISAPI rewrite 3、Php 5.5) で正常に動作する Yii プロジェクト (Yii 1.1.14) があります。
ただし、テスト サーバー (Linux、Apache 2.2、Php 5.5) では、リダイレクト以外はすべて機能します。ログイン コントローラーとインデックス コントローラーが相互にリダイレクトしているため、ホームページで無限のリダイレクト ループが発生しています (これはまったく発生しないはずです)。
ログイン アクションを URL (www.mysite.com/site/login) に入れると、ログインできます。しかし、コントローラー アクションでリダイレクトを行うと (たとえば、データを更新した後)、リダイレクト先のルートではなく、ホーム URL にスローされます。.htaccess 書き換えルールを使用しても違いはありません。そのため、Yii の構成と apache 固有の構成を組み合わせたものに違いないと思います...
これは私の urlManager 設定です:
'homeUrl'=>array('/site/index'),
'components'=>array(
'user'=>array(
'loginUrl'=>array('site/login'),
// disable cookie-based authentication
'allowAutoLogin'=>false,
'class'=>'MyWebUser'
),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'' => 'site/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>',
),
),
)
これは私の .htaccess ファイルです:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
# RewriteRule . index.php
RewriteRule ^(.*)\?*$ index.php?$1 [L,QSA]
そして、無限ループを引き起こしている私のサイト/ログインおよびサイト/インデックス アクション (ローカル マシンで期待どおりに動作します):
public function actionIndex()
{
if(Yii::app()->user->isGuest) {
$this->redirect('/site/login');
} else {
$this->render('index');
}
}
public function actionLogin()
{
// redirect to index page if user is already logged in
if(!Yii::app()->user->isGuest) {
$this->redirect(Yii::app()->homeUrl);
}
$model = new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['LoginForm'])) {
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login()) {
$this->redirect(Yii::app()->user->returnUrl);
}
}
// display the login form
$this->render('login',array('model'=>$model));
}
ルートの直接呼び出しは機能しますが、リダイレクトは機能しません。
編集:から に切り替える'urlFormat'=>'path'
と'urlFormat'=>'get'
、ルーティングが機能します。