How do I force HTTPS in Tomcat (through Apache and mod_jk)?
December 13, 2006 3:56 PM
Subscribe
I'm at my wit's end. I've been trying to configure tomcat (through apache 2 using mod_jk) to automatically re-direct all traffic to HTTPS from HTTP. More boring technical details to follow.
Specifically, I'm trying to get
CAS working. Tomcat is successfully serving-up the pages over HTTP and HTTPS and the application is working as expected. However, since this particular servlet handles user authentication I would like Tomcat to force HTTPS for all requests.
I have tried using isSecure() through JSP to redirect users but it simply puts the requests into an endless loop. I have tried the
following configuration in the web.xml file (see Lukas Bradleys' answer) and it does force a redirect, but it uses the server hostname as the URL and not the proxied URL to the server (which means it doesn't work externally).
I've tried changing the hostname on the server but it continues to use the initial hostname which leads me to believe that this value is somewhere in the Tomcat configuration, but I cannot locate it.
So, is there an easier way to do this? Or, does anyone know where to look to modify that hostname to use the URL for the proxied site? Any assistance would be appreciated.
posted by purephase to computers & internet (15 comments total)
RewriteEngine OnRewriteCond %{HTTPS} off
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [L,R]
You might want to test that first. You can use a second rule to limit it to certain urls, like
RewriteCond %{REQUEST_URI} /mydir/(.*).posted by boaz at 4:16 PM on December 13, 2006