Yii アプリケーションを、PHP5 と Apache2.x を実行する Ubuntu 12.04 サーバーにアップロードしました。.htaccess ファイルには以下が含まれます。
RewriteEngine on
RewriteBase /
/protected/controllers の UserController.php には以下が含まれます。
public function actionLogin()
{
$model= new Users();
// if it is ajax validation request
if(isset($_POST['ajax']))
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// print_r($_POST['Users']);
// collect user input data
if(isset($_POST['Users']))
{
$model->attributes=$_POST['Users'];
// validate user input and redirect to the previous page if valid
if($model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
}
サイトにログインすると、HTTP404 メッセージが表示されます。apache2 error.log の状態
file does not exist /var/www/users
この 404 エラーを修正するにはどうすればよいですか?
更新:
returnURL が評価されているようには見えません。ユーザーが前のページにリダイレクトされるように returnUrl を設定するにはどうすればよいですか?
UPDATE2: これは config/main.php のスニペットです:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
メインの .htacess ファイルの内容は次のとおりです。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*)\?*$ admin.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
php_value upload_max_filesize 20M
php_value post_max_size 21M
更新: 根本的な原因は、認証に使用されている UserIdentity クラスに関連しているようです。ユーザー モデルのスニペットを次に示します。
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,md5($this->password));
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 60*20; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else{
$this->addError('password','Incorrect username or password.');
return false;
}
}
ログインを完了するために、UserIdentity の代わりに CdbHttpSession を使用することをお勧めしますか?