I have a Tomcat instance running within our corp network.
Currently users can access it either by typing the machine name:
http://machine:8080
or by using the fully qualified name:
http://machine.company.com:8080
(This is only accessible internally)
However, I would like them to only use the full name. Is there a way to force a 301 redirect globally in tomcat (perhaps somewhere in server.xml, or conf.xml), where any resource accessed over the short name will forward (301) to the long name?
I’m not a fan of globally-configured things such as this, but you can globally-configure filters in Tomcat in
conf/web.xml. You can either write your own filter for this specific case, or use url-rewrite (http://www.tuckey.org/urlrewrite/) to do it for you. In either case, you will have to put your code (lr url-rewrite library) either in Tomcat’slibdirectory (yuck) or modify catalina.properties to re-introduce the “common” ClassLoader and place your code (or library) in there (also yuck).If you only have a single webapp deployed, then you can configure all of this in the one webapp and not bother with all the aforementioned “yucks”.
Also, if you have a web server out in front of Tomcat (say, Apache httpd), then of course you can do this kind of thing out at that level.