Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Use:

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! –  Nicholas Tolley 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. –  Nicholas Tolley Cottrell Oct 24 '12 at 9:50

Your Answer

 
discard

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.