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

I am running Apache 2.2 with Tomcat 6 and have several layers of URL rewriting going on in both Apache with RewriteRule and in Tomcat. I want to pass through the original REQUEST_URI that Apache sees so that I can log it properly for "page not found" errors etc.

In httpd.conf I have a line:


and in the mod_jk.conf, I have:


Which i thought should make the value available via request.getAttribute("ORIG_URL") in Servlets.

However, all that I see is "%{REQUEST_URI}", so I assume that SetEnv doesn't interpret the %{...} syntax. What is the right way to get the URL the user requested in Tomcat?

share|improve this question
up vote 1 down vote accepted


RewriteRule (.*) - [E=ORIG_URL:$1]
share|improve this answer
Yes, thanks! That did the trick. I added this as the first of the RewriteRules and now request.getAttribute("ORIG_URL") gets the value! – Nic Cottrell Oct 24 '12 at 9:48
@NicholasTolleyCottrell Hey, I'm glad it worked and thanks for teaching me about using JkEnvVar ORIG_URL to set servlet attributes - v. useful :) – Alastair McCormack Oct 24 '12 at 9:49

Use the getRequestURI() and getRequestURL() (and perhaps the getQueryString()) methods of the HttpServletRequest class.

share|improve this answer
Unfortunately this does not work since Apache has already manipulated the URL before passing it to Tomcat. So if my Apache rules change /node/blah to /node.jsp?id=blah, then getRequestURI sees the /node.jsp version. – Nic Cottrell Oct 24 '12 at 9:50

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.