htaccess SetEnv REDIRECT_ prefix

家住魔仙堡 提交于 2020-06-27 18:19:08

问题


I'm setting an environment variable in an htaccess file and it's being prepended with "REDIRECT_". As far as I've read, this is caused by URL rewriting.. the thing is, I'm not doing any rewriting (that I'm aware of).

My webspace contains two files:

.htaccess

SetEnv Foo "bar"

index.php

<?php
print_r($_ENV);

Now, I'm guessing this may have something to do with the fact that this is on a shared hosting package with 1&1.. is there anything else I should be checking or has anyone experienced this before? Or am I just missing something??

Cheers


回答1:


The issue is triggered by using PHP as a CGI Wrapper. If PHP is running as mod_php apache module it's not prefixing your variables.

Reason for that is internal redirect handling thus apache recreates the variables with the REDIRECT_ prefix :-/

Solution (updated)

Use PHP-FPM or mod_php

If you wanna use CGI Wrapping for PHP put this into your .htaccess:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]



回答2:


First of all your syntax for SetEnv is wrong. It should be like this:

SetEnv Foo "bar"

Then to access this field from PHP you need to do:

echo $_SERVER["Foo"];

Which should show up as "bar".



来源:https://stackoverflow.com/questions/21137640/htaccess-setenv-redirect-prefix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!