我有一个使用 Yii 框架制作的网站。我已将 HTTP 身份验证(基本)用于用户登录目的。它工作正常。并在身份验证后重定向到用户配置文件,但在 www 部分 https 之后的 url 被附加。例如。 https://wwwhttps.example.com/directory/我也尝试使用 .htaccess 删除 https 部分,但没有成功。这是我的 .htaccess 配置:
#Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# 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
#Basic ldap authentication goes here ...
RewriteCond %{HTTP_HOST} ^wwwhttps\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
和登录 Controller 代码:
public function actionLogin()
{
$this->layout='//layouts/login_layout';
if(isset($_SERVER['REMOTE_USER']) && $_SERVER['REMOTE_USER']!='')
{
$username = $_SERVER['REMOTE_USER'];
$user = User::model()->findByAttributes(array('username'=>$username));
$ui = UserIdentity::impersonate($user->id);
if($ui)
Yii::app()->user->login($ui, 0);
$this->redirect(yii::app()->getBaseUrl(true).'/user/profile');
}
}
是因为基本身份验证还是其他原因?如果我不使用基本身份验证,它工作正常......请帮助我。 提前致谢!!!
最佳答案
将 .htaccess ldap 验证码更改为,
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
因此整个 htaccess 如下所示,
#Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# 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
#Basic ldap authentication goes here ...
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
关于php - 基本身份验证重定向 url 修改后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20561352/