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

Let's say my browser issues a request to http://localhost/accounts?memberUuid=<some uuid>

I'd like apache2 to pickup that request, add a custom HTTP header with the uuid in it, strip the uuid param from the URL, and redirect to http://localhost:9000/accounts with the new custom header.

I'm a total apache noob. I have only used it as a simple web server for serving html, css, and javascript files. So I don't even know where to begin, otherwise I'd post some things I've tried so far.

Is this possible with apache2 alone? Do I need some additional tools running to accomplish this? Thanks!


This makes it look like I should be able to add whatever headers I want to a request. Or am I misunderstanding this? How would I use this along with an incoming value on the URL to send the header I need?

share|improve this question
Just to confirm, do you want clients to request the redirect URL with the custom header or do you want to send the custom HTTP header in your response? I don't think you can control client's request HEADER other than http-cookie I'd say. – mask8 Aug 1 '12 at 23:04
Yes, I was hoping I could have the clients request the redirect URL with a custom http header. If http-cookie is the only way to add values to the request via apache2, can you please demonstrate this? – Samo Aug 2 '12 at 1:55
@mask8: I made an update to my question. It looks to me like you should be able to add request headers of any sort but maybe I'm misinterpreting what I've read there. – Samo Aug 2 '12 at 2:01

It's not possible as described. The stateless nature of HTTP means that you cannot associate a current response with a future request unless you use a mechanism such as cookies.

share|improve this answer
Thanks. Can you show an example of setting a cookie and doing a redirect? And would it be possible to use a URL parameter as the cookie value? – Samo Aug 2 '12 at 2:25

To answer to your edited question about mod_headers, you are probably misunderstanding. The module lets you add additional request headers on server end. You can not force clients to send specific headers freely unless you have a communication rule over HTTP protocol b/w clients and server.

You can probably want to go with Cookie. you can use Set-Cookie header. I am not 100% sure if you can use cookie over sites running on different port, but I thought it could work as long as domain name is the same. About cookie, even wikipedia explains very well.

EDIT: I personally use php a lot so here is a very simple example to set Cookie and redirect in PHP:

// set cookie value
setcookie('uuid', $_GET['memberUuid'], time() + 3600);
// redirect
header('Location: http://localhost:9000/accounts');

and you can retrieve the cookie value by $_COOKIE['uuid'] on localhost:9000


If you only configure on apache, mod_headers won't be able to do this job since it doesn't handle GET variables as far as I know. Instead, mod_rewrite may work.

RewriteEngine On
RewriteRule ^/accounts\?memberUuid=(.*) http://localhost:9000/accounts [R,CO=uuid:$1:localhost:1440:/]

I didn't test this but I know mod_rewrite is capable of retrieving values from your URL, setting Cookies, and redirection.

share|improve this answer
Thanks for your response. Can you show an example configuration that writes a url parameter to a cookie and does a redirect? – Samo Aug 2 '12 at 2:24
@Samo I edited my answer. – mask8 Aug 2 '12 at 2:31
I was hoping to see what this would look like in an apache site definition. I don't want my server code to know this is happening. It's another system that will be adding this cookie when we go live, and I'm basically trying to mock out that system just using apache. – Samo Aug 2 '12 at 2:54
hehe ok @Samo. I updated once again :) – mask8 Aug 2 '12 at 3:21
Thanks, that looks a lot closer to what I'm looking for, but again, I'm a total noob. Where do I place these Rewrite directives? I also have a lot of questions about the syntax inside the brackets and the meaning of some of the values (especially 1440) but feel free to link me to something if the explanation is too lengthy! – Samo Aug 2 '12 at 3:57
up vote 0 down vote accepted

This turned out to be possible by combining RewriteRule with Proxy

<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{QUERY_STRING} ^(.*)memberUuid=(.*)$
  RewriteRule ^/(.*)$$1 [E=memberUuid:%2,P]
  ProxyPreserveHost On
  ProxyPass /excluded !
  ProxyPass /
  ProxyPassReverse /

  Header add iv-user "%{memberUuid}e"
  RequestHeader set iv-user "%{memberUuid}e"
share|improve this answer

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.