Search code examples
tomcathttp-redirectfqdn

Redirect Tomcat 9 to FQDN


i don't find an helpful awnser for my problem.

I have a Tomcat 9 with an "intranet website" and it works with https. Https works with the fqdn only.

Currently i have a redirect from http to https. (web.xml - security-constraint)

http://host to https://host work's with "certificate error - unsecure website".

With the Fqdn

http://host.v654.com to https://host.v654.com work's fine "without certicate error"

So i would like to redirect the "normal urls"

http://host to http://host.v654.com

and

https://host to https://host.v654.com

Thank You for help

Marcus


Solution

  • As already remarked in a comment, if you type https://host in your browser, you'll get a certificate error before your browser sends any request to Tomcat: your browser does not trust the server, why should it trust the redirect sent by the server?

    However you can modify the redirect from HTTP to HTTPS in such a way that http://host is redirected to https://host.example.com, by modifying the proxyName i redirectPort on your connector:

    <Connector port="80"
               proxyName="host.example.com"
               redirectPort="443"
               ...
               />
    

    The proxyName attribute fixes the hostname used in all URLs generated by Tomcat. By default the hostname provided by the HTTP client is used.