Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat 8.0 Rewrite Valve

Tags:

tomcat

I am trying to use the RewriteValve in Tomcat 8.0 http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html

In $CATALINA_HOME/conf/server.xml, I added

<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />

right below the Host tag

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">

Created a rewrite.config in the $CATALINA_HOME/conf directory with the following

RewriteRule ^/abc /myapp

where http:/host:port/myapp is a working webapp.

So now when I go to http://host:port/abc I expect to be redirected to http://host:port/myapp but I get a 404 the requested resource is not available instead.

It doesn't look like it is even reading my rewrite.config file. The access log in the logs directory just reports the "GET /abc HTTP/1.1" 404 1000 with no further details.

What am I missing? Thanks

like image 401
partlycloudy Avatar asked Nov 14 '14 14:11

partlycloudy


1 Answers

In Tomcat documentation http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html is written

The rewrite valve can be configured as a valve added in a Host. See virtual-server documentation for informations how to configure it. It will use a rewrite.config file containing the rewrite directives, it must be placed in the Host configuration folder.

so try to move rewrite.config into $CATALINA_HOME/conf/Catalina/localhost

Small hint: you can misspell something in rewrite.config ( e.g. xxRewriteRule ) and then if tomcat reads this file it fails. I think in your case tomcat starts even if you misspell something (because it is not read).

like image 96
michal4 Avatar answered Sep 18 '22 16:09

michal4