Php 修改基本身份验证后重定向url
我有一个网站使用Yii框架。我使用HTTP身份验证(基本)进行用户登录。它工作得很好。认证后,它重定向到用户配置文件,但在url中添加www部分https。我还尝试使用.htaccess删除https部分,但没有成功。以下是我的.htaccess配置:Php 修改基本身份验证后重定向url,php,.htaccess,url,yii,url-rewriting,Php,.htaccess,Url,Yii,Url Rewriting,我有一个网站使用Yii框架。我使用HTTP身份验证(基本)进行用户登录。它工作得很好。认证后,它重定向到用户配置文件,但在url中添加www部分https。我还尝试使用.htaccess删除https部分,但没有成功。以下是我的.htaccess配置: #Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCo
#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]
以及登录控制器代码:
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]
@Ronit Adhikari:环境变量可能有问题。您应该检查一下。我做对了,我必须在main.php中设置hostinfo和baseurl,因为我的webroot是公用文件夹中的目录:
request' => array(
'hostInfo' => 'https://www.example.com',
'baseUrl' => '/webroot',
),
请您发布与登录相关的代码,以及登录后的功能。你好,mazraara谢谢你的回复,我已经编辑了我的问题并添加了登录功能。你能删除.htaccess文件并重试吗。还有echo yii::app()->getBaseUrl(true)的输出是什么?“/user/profile”;出口当从htaccess文件中删除ldap身份验证代码时,它可以正常工作。yii::app()->getBaseUrl(true)的输出是例如,https附加了www partyes,这就是问题所在。必须相应地修改htcaccess。用您的HttAccessNope的总包含量更新问题我在不使用https之前尝试过它,但它仍然附加了以下代码:
RewriteCond%{HTTP\u HOST}^wwhttps\.(.*)$[NC]RewriteRule^(.*)$https://%1%{REQUEST\u URI}[R=301,QSA,NC,L]
它正在重定向到预期的url,但显示了重定向循环错误。请更新问题,包括更改后收到的错误。当重定向循环无限时,通常会出现此错误。i、 e index.php重定向到home.php,然后home.php重定向回index.php,这是一个无限循环..是的,我知道,但我已经检查过没有这样的重定向a