Tomcat – haproxy/apache/tomcat – no trailing slash results in a 301 redirection

apache-2.2haproxytomcat

I have this configuration in place:

haproxy(80,443) –> httpd(8443) –> tomcat(8096)

Going to https://websrv1/test will result in a 301 redirect to the httpd port for which
haproxy should be proxying requests.
So the user is redirected to http://websrv1:8443/test.

But, if the user goes to https://websrv1/test/ - specifying a the trailing slash – it works just fine.

How can I prevent this redirection from happening, when the user DOES NOT specify a trailing slash?

  • haproxy configuration?
  • apache url rewrite?
  • tomcat url rewrite?

Best Answer

The problem is on the Apache level.

You could try to set

UseCanonicalName On

and

ServerName websrv1:80

in your Apache config to make apache use the correct rewrite.

Alternatively you could disable the rewrite of the trailing slash with

DirectorySlash Off

See UseCanonicalName, ServerName and DirectorySlash

Related Topic