mkyrc
Jun 22, 2021Cirrus
Solved
How to replace [HTTP::host] using regex
Hi all,
I'd like to replace Host information in HTTP header with regexp because I need read dynamic part of (sub)domain.
I need change this (example):
(.*).domain.com -> %1.newdomain.com
First part of domain (3rd level in this example) is dynamic, therefore I need regex. How does the irule look like? Can anybody help me find solution? thx.
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).