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

我有一个使用Yii框架制作的网站.我已经使用HTTP身份验证(基本)进行用户登录.它工作正常.在身份验证之后,它会重定向到用户配置文件,但是在附加了www部分https之后的url中.eg. 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]

和登录控制器代码:

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]

标签:htaccess,php,url-rewriting,url,yii

来源: https://codeday.me/bug/20190825/1717994.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx是一个开源的高性能Web服务器,它可以用来处理静态内容和动态请求。在使用Nginx的过程中,有时我们需要将客户端请求的URL重定向到其他的URL,实现URL的跳转。以下是Nginx重定向到其他URL的方法: 使用rewrite指令进行URL重定向 在nginx.conf配置文件中,可以使用rewrite指令对URL进行重写或重定向,例如: location /oldurl { rewrite ^/oldurl(.*) https://newurl.com/newurl permanent; } 上述代码表示,当客户端访问/oldurl时,将它重定向到https://newurl.com/newurl。其中,permanent表示使用301重定向方式。 使用return指令进行URL重定向 除了rewrite指令,Nginx还提供了return指令,也可以用来实现URL重定向。例如: location /oldurl { return 301 https://newurl.com/newurl; } 上述代码表示,当客户端访问/oldurl时,将它重定向到https://newurl.com/newurl。其中,301表示使用永久重定向方式。 使用proxy_pass指令进行URL重定向 proxy_pass指令是Nginx中用来进行反向代理的指令,但是它也可以用来实现URL重定向。例如: location /oldurl { proxy_pass https://newurl.com/newurl; } 上述代码表示,当客户端访问/oldurl时,将它重定向到https://newurl.com/newurl。但是,这种方式的重定向需要后端服务器返回301或302状态码才能生效。 综上所述,Nginx提供了多种方式实现URL重定向,开发者可以根据具体需求自行选择。而且Nginx的性能和功能十分强大,深受广大开发者的青睐。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值