Use Case: Need to create vanity host name to whitelabel service. Need to rewrite URL so everything as works as normal just new URL. I would like to initially push users to a login to a specific subtenant and then once logged in can continue to use as normal.
Example:
portal.company1.com --> this is by default the main URL that the company 1 uses to login. We create tenants which then allows them without vanity url to go to portal.company1.com/login/account/company2 once logged in the app drops the /login/account/company2 all together and just leverages the continued portal.company1.com/
We are wanting to point lod.company2.com to our haproxy and rewrite the URL so it completely replaces the portal.company1.com with the new vanity url and they can access their tenant under their new URL.
I have been looking through a number of different stack overflows to find the method to do this so far been a bit of a struggle.
config with different tests listed below: Understanding that these are not functioning... just keeping them around to show my work so far.
frontend https_443_frontend
mode http
# --- TESTS SO FAR --- ###
#http-request replace-value Host portal.company1.com lod.company2.com if { hdr(host) -i lod.company2.com }
#redirect prefix portal.company1.com code 301 if { hdr(host) -i lod.company2.com }
#http-request set-header Host lod.company2.com if {hdr(host) -i lod.company2.com }
#http-request replace-header Host portal.company1.com/login/company2 lod.company2.com if { hdr(host) -i lod.company2.com }
#redirect prefix https://portal.company1.com code 301 if { hdr(host) -i lod.company2.com }
acl host_company1_portal_443 hdr(host) -i portal.company1.com
acl host_lod.company2.com_443 hdr(host) -i lod.company2.com
use_backend apptier_backend if host_company1_portal_443
use_backend lod_company2 if host_lod.company2.com_443
backend lod_company2
mode http
# option httpclose
# option forwardfor
# http-request set-header Host lod.company2.com if { hdr(host) -i portal.company1.com }
#cookie SERVERID insert indirect nocache
#########
#http-request replace-value Host portal.company1.com lod.company2.com if { hdr(host) -i lod.company2.com }
#redirect prefix portal.company1.com/login/company2 code 301 if { hdr(host) -i lod.company2.com }
#http-request set-header Host lod.company2.com if {hdr(host) -i lod.company2.com }
http-request replace-header Host portal.company1.com lod.company2.com if { hdr(host) -i lod.company2.com }
#redirect prefix https://portal.company1.com/login/company2 code 301 if { hdr(host) -i lod.company2.com }
End Goal:
when users hits lod.company2.com -- it takes them to their tenant login. Leveraging that host name as a rewrite instead of a redirect. The goal is to mask the underlying portal.company1.com but still have everything function on the backend.
Ok after a few rounds of trying to figure this out... we finally have a solution that appears to be working.
The one line we needed on the front end.
http-request replace-value Location ^portal.company1.com(.*) lod.company2.com\1 if { hdr(host) -i lod.company2.com }
Two lines we needed in the backend
http-request replace-value Location ^https://lod.company2.com(.*)$ https://portal.company1.com\1
http-response replace-value Location ^https://portal.company1.com(.*)$ https://lod.company2.com\1