Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


...which prints out all the environment variables.

When I go to, I get the output:

    [DOCUMENT_ROOT] => ********
    [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_URI] => ********
    [SCRIPT_FILENAME] => ********
    [SCRIPT_NAME] => ********
    [SERVER_ADDR] => ********
    [SERVER_ADMIN] => ********
    [SERVER_NAME] => ********
    [SERVER_PORT] => 80
    [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

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


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.