Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I'm trying to add a header value to every request via Apache (ver 2.2). I've edited my VirtualHost to include the following vaiations: (I've tried both RequestHeader and Header, add and set in all of these cases)

RequestHeader set X-test_url "Test"


<Directory />
  RequestHeader set X-test_url "Test"


<Location ~ "/*" >
  RequestHeader set X-test_url "Test"

It's hard to explain how I've gotten to this point, but I have to get this done in Apache. Again I'm trying to add the header value to every request. Thanks.

share|improve this question
up vote 1 down vote accepted

So your first ought work alright. I've just tested the following. On a Red Hat system, I added RequestHeader add X-LocalHeader "Headers For the Win" to my httpd.conf file.

Then, I put together a quick Python script to dump my environment:


import os
print 'Content-type: text/plain'

for tup in os.environ.items():
    print '%s: %s' % tup

Finally, an Apache restart and a curl yields the following:

[jeff@marvin ~]$ curl http://localhost/cgi-bin/
HTTP_USER_AGENT: curl/7.19.7 
SERVER_NAME: localhost
SCRIPT_FILENAME: /var/www/cgi-bin/
SERVER_SOFTWARE: Apache/2.2.13 (Fedora)
SERVER_ADMIN: root@localhost
SCRIPT_NAME: /cgi-bin/
SERVER_SIGNATURE: Apache/2.2.13 

HTTP_HOST: localhost
PATH: /sbin:/usr/sbin:/bin:/usr/bin
REQUEST_URI: /cgi-bin/
HTTP_X_LOCALHEADER: Headers For the Win
DOCUMENT_ROOT: /var/www/html

As you can see, I have an 'HTTP_X_LOCALHEADER' value set, which corresponds to the header we added earlier. It looks like you had it right, is it still not working?

share|improve this answer
Yeah, that's what I thought too. For some reason it's not coming through. Did you add it to your httpd.conf inside a virtual host or outside of one? The docs listed RequestHeaders as only valid inside of certain nodes, one of which was virtualhost. – meleager Mar 17 '10 at 20:57
Our config uses multiple files so I was trying to avoid editing the httpd.conf. That being said I found a Directory node in the httpd.conf that matches all directories and adding the RequestHeader worked. Thanks for the advice and nice to see a hockey fan. – meleager Mar 17 '10 at 21:06

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.