I’m writing this down because it too me an age to figure out a way of doing this. I have a website which Tomcat is happily serving. Areas of the site require a secure connection so I’m using Spring security to require particular URLs to be accessed over HTTPS. It means that when I access http://example.org:8080/webapp/login, it’ll bump me to https://example.org:8443/webapp/login. Note: Tomcat is setup with the SSL connector and a self signed .keystore see (http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html).
I have two vhosts setup in Apache, one for the http://example.org and one for https://example.org. They are both using mod_proxy to ProxyPass and ProxyPassReverse requests to the appropriate Tomcat URL’s. The problem comes when switching to HTTPS from HTTP and vice versa. Ideally I wanted some sort of ProxyPassReverse declaration in my config for http://example.org what would change HTTP headers (that Spring sets) for https://example.org:8443/webapp into https://example.org. Except ProxyPassReverse doesn’t work like that.
Now, I realise I could simply not use Spring to manage which parts of the site should be accessed over HTTPS and which should not…and just setup Apache to redirect as appropriate. I don’t want to do that though, because that makes the task of adding these restrictions a deploy time task, rather than a development time task. I don’t want to risk someone forgetting to add new restrictions when deploying the webapp and I’d much rather the developer added these restrictions when they were working on the task and really thinking about where and when they are needed.
So, how do I solve the problem so that the app can manage its secure-ness and I can setup Apache once and forget about it? The answer is to ProxyPassReverse onto a “special” URL, which when accessed will redirect to the HTTPS (or HTTP) site. For example, if the HTTP site needed to redirect to the HTTPS site, I’d add rules like so to perform the redirect:
# Proxy a request (from the server) to switch to https onto a special URL "/2https/"
ProxyPassReverse /2https/ https://example.org:8443/webapp/
# When a client requests a URL prefixed with "/2https" map it onto the secure site
RewriteRule ^/2https/(.*)$ https://example.org/$1 [R,L]
…and you’d add something similar to the secure site Apache config. As long as I don’t mount any pages at /2http or /2https I should be ok. Note a couple of things:
- You’ll need “SSLProxyEngine on” and “RewriteEngine on” and obviously the appropriate Apache modules loaded for these commands.
- Because of the redirect between HTTP <-> HTTPS you won’t be able to POST data between them directly (I’m not sure why you’d NEED to though)
- Obviously you’ll need to setup Apache with an SSL certificate…but that is a different story
I should say a special thanks to this random site – from whence the idea actually came from. If anyone has any better ideas on how to do it I’d love to hear them. Please comment below.
BestValueStore – Finding deals is easy and the product info is very clear.
smartbuyingeco – Informative and eco-aware, helping consumers purchase responsibly without hassle.
alliancesexpert – Informative and reliable, alliance advice is easy to follow and implement.
UrbanBoutiqueSpot – Small-scale urban retail focus gives a curated feel for city shoppers.
ProEnterpriseFramework – Clear and organized, frameworks are explained logically and effectively.
ClarityPathClick – Provided actionable insights that improved my overall approach.
reliableonlinecommerce – Safe and reliable, buying products online feels simple and secure today.
QuickPickShop – Made understanding deals and offers straightforward and fast.
relationship hub insights – Helpful tips, professional connections feel achievable.
explore now – Pages load instantly, simple navigation, content is easy to understand
CorporateNetworkSafe – Clear and actionable advice, platform inspires confidence for team bonding.
efficient solutions hub – Guides users toward improved methods for problem solving.
Professional Connections Lab – Clear advice for strengthening relationships across business networks.
pixelpilot.click – Bookmarked this immediately, planning to revisit for updates and inspiration.
enterprise partnerships hub – Messaging is concise and tailored to helping companies collaborate effectively.
digital shopping space – Modern design keeps navigation simple and enjoyable.
biznetworkcentral – A clear resource for understanding how business networks operate smoothly.
go to site – Clean design, easy navigation, information is straightforward
tavro page – Fast-loading site with clear sections and simple navigation
new market angles – Encourages exploring unconventional market approaches for business growth.
vyrxo homepage – Pleasant to browse, navigation is intuitive and pages load fast
success pathways – Very helpful content, simplifies planning and implementing growth.
enterpriseconnectionsguide – Practical platform, long-term business connections are explained clearly and effectively.
ThoughtfulPurchaseNetwork – Emphasizes smarter buying practices within an organized online ecosystem.
signal turns action portal – Easy to browse, clear headings, and content flows naturally
FindSmarterBusinessMoves – Found this resource valuable, explanations are concise and easy enough.
global alliance insights – Clear international partnership ideas, content is easy to follow.
click here – Minimalist layout, fast pages, easy to find information
searchspark.click – Navigation felt smooth, found everything quickly without any confusing steps.
SmartSavingsCart – Highlights smart and value-focused shopping experiences.
GlobalNetworkingGuide – Clear and professional, building international relationships is effortless.
Growth Mindset Hub – Encouraging ideas that support gradual but meaningful progress.
smart shopping site – Clear value orientation, great for shoppers looking for savings.
greenenterprisealliance – Provides actionable steps to develop sustainable and long-lasting partnerships.
reliable shopping portal – Platform feels dependable, and payment steps are easy to follow.
fast track purchases – Highlights quick and convenient options for completing orders.
InsightClarityNetwork – Emphasizes clear analysis and strategic thinking for effective business outcomes.
zylor online – Neat layout, smooth scrolling, and content is accessible quickly
LearnFutureFocusedSkills – Solid website with practical tips I can apply immediately today.
focusamplifiesgrowth home – Simple interface, pages are easy to follow, and content is clear
strategic insight click – Guides understanding of strategic processes without feeling overwhelming.
CartQuick – Secure and hassle-free, checkout takes no time.
resource page – Lightweight and clear, navigation feels smooth and logical
korixo corner – Easygoing site with a neat and user-focused layout
small shop platform – Simple and practical, makes starting ecommerce stress-free.
Strategic Collaboration Lab – Practical insights that simplify creating strong, long-term partnerships.
LearnStrategyNow – Practical guidance, strategy planning is clear and easy to follow.
globalpartnershipinfrastructure – Very detailed, global partnership infrastructure is explained clearly and practically here.
growthframeworks – Provides actionable insights for developing expertise and career competence.
CommercialBondInsights – Provided the clarity I needed to make confident decisions.