php - 基本身份验证重定向 url 修改后

标签 php .htaccess url yii url-rewriting

我有一个使用 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/

相关文章:

.htaccess - AllowOverride 安全问题

apache - 使用一个 301 重定向重定向到 https 和 www

c# - url 字符串中的斜杠 (c#)

javascript - 为什么我无法从单选按钮获取值?

php - 如何检查 PECL 扩展名是否存在?

php - 我如何对这个 ajax php 脚本进行排序

php - 在WAMP服务器中将存储引擎从InnoDB更改为MYISAM

wordpress - .htaccess 覆盖父 .htaccess

php - parse_url 为 url : 'www.example.com' 返回空字符串

wordpress - 在 WordPress PHP 中将长域 URL 重写为短域 URL