Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is just plain weird.

I have put the following in an .htaccess file:

RewriteRule ^a-file-on-the-server$ index.php [E=let_me_in:test]

And in my PHP script, I have the following:

print_r($_ENV);

...which prints out all the environment variables.

When I go to mydomain.com/a-file-on-the-server, I get the output:

Array
(
    [DOCUMENT_ROOT] => ********
    [GATEWAY_INTERFACE] => CGI/1.1
    [HTTP_ACCEPT] => application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_CONNECTION] => keep-alive
    [HTTP_COOKIE] => ********
    [HTTP_HOST] => ********
    [HTTP_USER_AGENT] => Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
    [PATH] => /bin:/usr/bin
    [QUERY_STRING] => 
    [REDIRECT_STATUS] => 200
    [REMOTE_ADDR] => ********
    [REMOTE_PORT] => 36345
    [REQUEST_METHOD] => GET
    [REQUEST_URI] => ********
    [SCRIPT_FILENAME] => ********
    [SCRIPT_NAME] => ********
    [SERVER_ADDR] => ********
    [SERVER_ADMIN] => ********
    [SERVER_NAME] => ********
    [SERVER_PORT] => 80
    [SERVER_PROTOCOL] => HTTP/1.1
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache
    [UNIQUE_ID] => ********
)

As you can see, the environment variable is not showing up. What am I doing wrong?

share|improve this question

2 Answers 2

The one thing that looks wrong is the regex you're using. Remember that the regex matches the whole request URI, which always starts with a /. The way you've written it, it'll only match if the request starts with a a-file... which will never be the case.

Try using this instead (I've only added a / after the ^):

RewriteRule ^/a-file-on-the-server$ index.php [E=let_me_in:test]

There might be other parts of your rule that aren't right, but I don't have a lot of experience with environment vars.

share|improve this answer

hey I am doing some test and when setting env var,

I do what you do like [E=variable:value,other flag/value,(..)]

and in my php file I see those vat settings in $_SERVER['variable']

you might want to get your var like that:

echo $_SERVER['let_me_in'];

shoult output test.

share|improve this answer
    
I'm afraid that I don't understand your answer. –  Nathan Osman Sep 22 '10 at 3:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.