1

I deployed my WAR-file containing a running Java Spring/AngularJS application to a Tomcat8 which is running behind an Apache2 with the following config:

<VirtualHost *:80>
    ServerName example.de
    ServerAlias www.example.de

    ProxyPass / http://localhost:8080/example/
    ProxyPassReverse / http://localhost:8080/example/

    <Location "/">
      Order allow,deny
      Allow from all
    </Location>
 </VirtualHost>

So far so good, this is running. Now I wanted to switch to HTML5-mode, so I solved all the prerequisites on the client-side.

For the backend I started with exposing the Tomcat webapp to http://www.example.de:8080/example/ to add rewrite rules for Tomcat8. First I tried out with Tuckeys UrlRewriteFilter and then noticed, that there is a RewriteValve for Tomcat8, now.

So I created a WEB-INF/rewrite.config in the application now:

RewriteCond %{REQUEST_URI} ^/(css|img|js|templ|api|config|userdata|fonts).*$
RewriteRule ^.*$ - [L]

RewriteRule ^.*$ /index.html [L,QSA]

My /opt/tomcat/conf/context.xml looks like that:

<Context usehttponly="true">
    <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
</Context>

When hitting localhost:8080/example/ now, EVERY request is rewritten to index.html, so probably all assets contain the contents of index.html. At least rewriting is enabled now, but it's not doing what I want.

Can someone find something that I'm doing wrong here? Is there a possibility to debug this? I'm feeling like stepping in the dark right now.

If it helps, this is my WEB-INF/web.xml, located in the application: https://gist.github.com/JonasPriest/998099c509b2173ba3b1

Is there maybe a solution to delegate rewriting to the Apache2 instead of Tomcat?

jpietzsch
  • 536
  • 5
  • 18
  • I hit this earlier today and saw that http://stackoverflow.com/questions/28767585/tomcat-8-url-rewrite explains how to do the setup, minus the Apache httpd part of your equation. – Joe Rinehart Oct 29 '15 at 11:43
  • Thanks, I already saw every Stackoverflow questions regarding this topic and googled the shit out of it. I tried everything but it's still not working completely. – jpietzsch Oct 29 '15 at 15:06
  • Looking at your edits, I think your .config file is in the wrong place. It's not a web-app level deal. Try moving rewrite.config out of WEB-INF and into Tomcat's conf/Catalina/localhost. – Joe Rinehart Oct 29 '15 at 15:27
  • Unfortunately this does not change anything. I'm gettin' really depressed on that topic... – jpietzsch Nov 01 '15 at 22:24
  • this article may help you. http://tonyjunkes.com/blog/a-brief-look-at-the-rewrite-valve-in-tomcat-8 – xkeshav Sep 14 '16 at 12:26

1 Answers1

0

Tomcat can't find '/example/test' in it's route,when your server recive url 'http://localhost:8080/example/test', you should return 'http://localhost:8080/' , and '/example/test' will work in angular routes

Cr.
  • 886
  • 7
  • 12
  • I do not understand the idea behind that suggestion. What do you mean by 'you should return 'http://localhost:8080/''? – jpietzsch Oct 29 '15 at 10:14
  • @JonasPriest return the home page like index.html no matter what you recived. – Cr. Oct 30 '15 at 01:19