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?

2 Answers 2

1

Use:

RewriteRule (.*) - [E=ORIG_URL:$1]
2
  • Yes, thanks! That did the trick. I added this as the first of the RewriteRules and now request.getAttribute("ORIG_URL") gets the value! Oct 24, 2012 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 :) Oct 24, 2012 at 9:49
0

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

1
  • 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. Oct 24, 2012 at 9:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .