Forum Discussion
How to replace [HTTP::host] using regex
- Jun 23, 2021
My solution without "regex":
HTTP::header replace Host [string map -nocase {".domain.com" ".newdomain.com"} [HTTP::host]]
The level 3 (or 4) subdomain is untouched. This solves my problem.
I'd like to know solution with regex, because sometimes is helpful string manipulation like this: foo.domain.com -> foo.com (in this case is 'foo' is unknown, therefore is regex helpful).
Hi Martin,
Let me have a look if I understand this correctly; you want to replace the Host header if the last parts of the header contain a certain domain, irrespective of what the subdomain looks like?
when HTTP_REQUEST {
if { [HTTP::host] ends_with ".domain.com" } {
HTTP::host "www.blabla.com"
}
}
Hope this helps, but please shout if I have misunderstood your question.
Thanks for reaction Alex. This is not good example.
I need modify Host string from "unknown.sub.domain.com" to "unknown.nedomain.com". In other words, I need keep 'unknown' and change only end part of domain ('sub.domain.com' -> 'domain.com'). Solution for this case is below. Your example replaces Host part statically (*.domain.com -> www.newdomain.com).
I'm migrating configuration from other vendor's device to f5 and there is regex used for string manipulation. Therefore my question was directed to regex. But in this case it's not needed (string map is helpful).
Recent Discussions
Related Content
* 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