简体   繁体   English

与Apache一起使用mod_rewrite时如何传递REMOTE_USER环境变量?

[英]How can I pass REMOTE_USER environment variable when using mod_rewrite with Apache?

I have the following Apache config: 我有以下Apache配置:

Alias /HelpdeskSignIn/ /opt/HelpdeskSignIn/web/
    <Location /HelpdeskSignIn/>
            Order allow,deny
            Allow from all
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*) app.php [E=RU:%1,QSA,L]
            RequestHeader set REMOTE_USER %{RU}e
            RedirectMatch permanent ^/app\.php/(.*) /$1
    </Location>
    <Location /HelpdeskSignIn/cccs>
            AuthType CAS
            Require valid-user
    </Location>

The root of the app does not need authentication, but if someone goes to a sub directory of that it needs to be authenticated. 应用程序的根目录不需要身份验证,但是如果有人进入该目录的子目录,则需要对其进行身份验证。 If I require a valid CAS user on the whole thing and check the value with PHP it works, but when I try the code above the REMOTE_USER is always empty when hitting PHP code within /cccs. 如果我在整个过程中都需要一个有效的CAS用户并使用PHP来检查其值,那么它可以工作,但是当我尝试上面的代码时,在/ cccs中打PHP代码时REMOTE_USER始终为空。 I've tried a few ways of passing that environment variable on the rewrite, but it doesn't seem to work. 我尝试了几种在重写时传递该环境变量的方法,但是它似乎不起作用。 Is this possible or is there a better way of doing it? 这可能还是有更好的方法呢?

@mario had the answer! @mario有答案! My issue was I kept trying to set the variable on the rewrite, but what I didn't care how I got the value... I did not know that it was possible it was set to REDIRECT_REMOTE_USER, which it was. 我的问题是我一直试图在重写中设置变量,但是我不在乎如何获取值...我不知道它是否有可能被设置为REDIRECT_REMOTE_USER。

For what its worth, using redirects with nginx and php-fpm and fastCGI this does not happen with frameworks. 对于它的价值,将重定向与nginx和php-fpm和fastCGI一起使用不会在框架中发生。 In my case, I was using a framework. 就我而言,我使用的是框架。

This is a somewhat similar question that didn't come up in ANY of my searches as I wasn't Googling correctly: has some useful info on the subject: Accessing REMOTE_USER from PHP/CakePHP 这是一个有点类似的问题,因为我搜索不正确,所以没有出现在我的任何搜索中:有关此主题的一些有用信息: 从PHP / CakePHP访问REMOTE_USER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM