When a user first hits our server, we want to capture some information about the incoming request:
Referer header, &c. The general idea is that when we get an incoming request that matches some
RewriteConds (doesn't have a cookie, doesn't have a particular
GET param in case they don't accept cookies, &c.), we use a
[P] to transparently proxy the request to a servlet (actually a Spring controller, if that matters) that will analyse the incoming request, then send a 302, with a new cookie set, to redirect the user to the originally requested URL. That is,
- User requests
mod_rewritedetects that this is the user's first request (no cookie, no
- Servlet analyses the request and responds with a 302 to
The first three steps are simple enough. The problem is that in step four, the servlet has no idea that
/foo.html was ever requested, which means (a) it can't record the fact that such was the case (a business requirement) and (b) it doesn't know where to redirect. We can see which server was requested in
X-Forwarded-Host et al, but looking at the request URL just shows
What we want to achieve, then, is ideally a proxy pass transparent not just to the client but to the receiving servlet as well.
One option is to pass the URL in an environment variable with something like
[E=FOO:REQUEST_URI]. However, this increases the complexity of the servlet, and it's not obvious to me whether the request is otherwise unchanged. The point of the servlet is to analyse the request coming from the client, preferably unchanged by Apache. If
mod_rewrite changed the request URL, can I trust all other aspects of the request to be unchanged?