Forum Discussion
Dbow_21284
Nimbostratus
May 18, 2010Rewrite Host Header iRule on VS that changes to HOST Header on same VS
Hello guys,
I have a situation where our developers have a sight running on HTTPS that needs to rewrite the host header to a new host header, but DNS points it to the same VS on my LTM. I do have a clientssl profile so I can decrypt the traffic.
Important Points to consider:
1) I need to rewrite any requests that goto mydomain.net to sub.mydomain.net
2) DNS for mydomain.com and sub.mydomain.net both point to the same VS on the LB.
I have tried redirect iRules and HOST::HEADER replace iRules on my VS, but it doesn't appear to work. Here are examples of what I have done:
iRULE1:
Rewrite Host Header iRule
when HTTP_REQUEST {
if { [HTTP::host] equals "mydomain.net" } {
Rewrite host
HTTP::header replace Host sub.mydomain.net
}
}
iRULE2:
Redirect to sub.mydomain.net
when HTTP_REQUEST {
if {[HTTP::host] equals "mydomain.net" } {
HTTP::redirect https://sub.mydomain.net }
}
I am not sure why this doesn't work. I have used similar rules elsewhere. The only difference in those situations where it worked fine, is that the rewrite of the host header or redirect pointed to domain name that goes to different VS. Not sure if that is my issue. In both situations, the LB just lets the user access mydomain.com and nothing gets changed. I must be missing something here.
Any ideas as to why this wouldnt work or other approaches? Thanks in advance!
Denbownium
- Michael_Yates
Nimbostratus
Your second iRule should work if you put quotes around the redirect:when HTTP_REQUEST { if {[HTTP::host] equals "mydomain.net" } { HTTP::redirect "https://sub.mydomain.net" } }
when HTTP_REQUEST { if {[HTTP::host] equals "mydomain.net" } { set host [string map {mydomain.net sub.mydomain.net} [HTTP::host]] HTTP::redirect "https://$host[HTTP::uri]" } }
- Dbow_21284
Nimbostratus
Yeah I have tried both and it does not work. Weird! - hoolio
Cirrostratus
Hi Denbownium, - Dbow_21284
Nimbostratus
OK I will analyze the response headers and post what I find. - hoolio
Cirrostratus
I assumed the issue was a mismatched cert warning when a client used the "wrong" hostname. If you have a cert which is valid for both hostnames, that shouldn't be a problem. - Dbow_21284
Nimbostratus
Well actually nothing fails. ... The developers are really **bleep** about the URL being switched to www.mydomain.com in the browser. I think there is a big push from marketing on this as well. ... Dont even get me started.when HTTP_RESPONSE { set nowwwHost "mydomain.com" set wwwHost "www.mydomain.com" set location [HTTP::header location] if { $location starts_with $nowwwHost } { regsub -all $nowwwHost $location $wwwHost newLocation HTTP::header replace location $newLocation } }
- spark_86682Historic F5 AccountWell, if you're talking about the location bar in the clients' browser, then all the header fiddling in the world won't change that. You need to do a redirect to the new location, something like:
when HTTP_REQUEST { if {[HTTP::host] equals "mydomain.net" } { HTTP::redirect "https://sub.mydomain.net[HTTP::uri]" } }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects