0

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:

SetEnv ORIG_URL %{REQUEST_URI}

and in the mod_jk.conf, I have:

JkEnvVar ORIG_URL

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?

1

Use:

RewriteRule (.*) - [E=ORIG_URL:$1]
  • 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
0

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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.