tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Redirection/URL rewriting Tomcat 8.5.14
Date Fri, 12 May 2017 17:31:50 GMT
Hash: SHA256


On 5/12/17 10:03 AM, Daniel Savard wrote:
> Hi everyone,
> my question is not specific to the Tomcat version specified in the 
> subject line. I am trying to implement a URL rewrite or
> redirection using Tomcat. What I want to do is the following:
> In a given instance of Tomcat, I have each application context
> setup using the xml files in
> $CATALINA_BASE/conf/[enginename]/[hostname]/, so far so good. Hence
> for app1 I then have the URL:
https://myserver:myport/app1, etc.
> What I need to do, is to have a dummy application which purpose is 
> just to redirect/rewrite the URL from one application to another.
> So, I need in fact an empty application capturing each request and
> send back to the browser a rewritten URL to the another
> application.
> For example, suppose I want to redirect app1 to app2, I need to
rewrite all
> possible URL with query options and so one replacing only app1 by 
> app2 in the URL.
> https://myserver:myport/app1/something_more_specific?opt1 should be
>  rewritten as 
> https://myserver:myport/app2/something_more_specific?opt1
> To do this, I read about the rewrite valve here: 
> So, I created an empty directory $CATALINA_BASE/webapps/app1 with 
> the following file:
> $CATALINA_BASE/webapps/app1/WEB-INF/rewrite.config
> And my $CATALINA_BASE/conf/[enginename]/[hostname]/app1.xml has the
>  following entry within its context:
> <Valve
> className="org.apache.catalina.valves.rewrite.RewriteValve"/>
> My rewrite.config file is as follow:
> RewriteCond %{REQUEST_URI} ^/app1/?.* RewriteRule ^/app1(/?.*)$ 
> /app2$1 [L]
> Without anything else, I am getting a HTTP 404 code. With an empty
>  index.html I am getting a blank page. Within a working application
> I am getting the application's welcome page. But never the URL is
rewritten. The
> rewrite.config file is actually read, I checked by introducing
> some typo and I am getting an error message at startup.
> Is there a way to debug this problem? How can I see what is going
> on with the execution of the rewriting class?

I think everything you have above is correct, except that you want to
deploy everything in the ROOT application instead of into "app1". With
"app1", you are re-writing "/app1/app1" to "/app1/app2" when in fact you
want to rewrite "/app1" to "/app2", correct?

Also, it's important that /app1 not be a deployed application, otherwise
requests to that context path with be sent to the /app1 application
instead of to the ROOT webapp.

- -chris
Comment: GPGTools -
Comment: Using GnuPG with Thunderbird -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message