17-Oct-2022 02:56
Dears,
I am wondering about an efficient procedure to search and replace a specific Subdomain in the HOST, What i want to achieve is rewrite the HTTP request toward the server side as follows:
Client Request: DIRx.Clust1.Domain.com ----Should be forwarded to server side as follows:--- DIRx.Clust2.Domain.com, Only rewrite the Clust1 to Clust2 in the HOST, noting that the x value is variable DIRx and keep changing so i am unable to achieve the rewrite by simple Rule to replace the whole domain, i want to have a universal rule that can match the DIR# and copy it successfully to the domain when the rewrite happened.
Please can you guide me if there is any useful workaround.
Regards,
Muhannad
Solved! Go to Solution.
17-Oct-2022 05:57
Code above is case sensitive on HTTP::host match.
If you want a case-insensitive match you can run this instead
when HTTP_REQUEST {
# log local0. "Client requested host: [HTTP::host]"
if { [string tolower [HTTP::host]] starts_with "dir" && [string tolower [HTTP::host]] contains "clust1" }{
HTTP::header replace Host [string map {"clust1" "clust2"}[string tolower [HTTP::host]]]
# log local0. "Modified host: [HTTP::host]"
}
}
Oct 17 15:43:07 bigip info tmm7[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Client requested host: DIR000.Clust1.Domain.com
Oct 17 15:43:07 bigip info tmm7[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Modified host: dir000.clust2.domain.com
17-Oct-2022 05:47
when HTTP_REQUEST {
if { [HTTP::host] starts_with "DIR" && [HTTP::host] contains "Clust1" }{
HTTP::header replace Host [string map {"Clust1" "Clust2"}[HTTP::host]]
}
}
Sample execution logs:
Oct 17 15:32:37 bigip info tmm[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Client requested host: DIRx.Clust1.Domain.com
Oct 17 15:32:37 bigip info tmm[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Modified host: DIRx.Clust2.Domain.com
Oct 17 15:32:41 bigip info tmm6[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Client requested host: DIRy.Clust1.Domain.com
Oct 17 15:32:41 bigip info tmm6[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Modified host: DIRy.Clust2.Domain.com
Oct 17 15:32:43 bigip info tmm6[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Client requested host: DIRz.Clust1.Domain.com
Oct 17 15:32:43 bigip info tmm6[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Modified host: DIRz.Clust2.Domain.com
17-Oct-2022 05:57
Code above is case sensitive on HTTP::host match.
If you want a case-insensitive match you can run this instead
when HTTP_REQUEST {
# log local0. "Client requested host: [HTTP::host]"
if { [string tolower [HTTP::host]] starts_with "dir" && [string tolower [HTTP::host]] contains "clust1" }{
HTTP::header replace Host [string map {"clust1" "clust2"}[string tolower [HTTP::host]]]
# log local0. "Modified host: [HTTP::host]"
}
}
Oct 17 15:43:07 bigip info tmm7[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Client requested host: DIR000.Clust1.Domain.com
Oct 17 15:43:07 bigip info tmm7[11345]: Rule /Common/test-iRule <HTTP_REQUEST>: Modified host: dir000.clust2.domain.com
19-Oct-2022 05:40
This is working perfectly thanks :).
25-Oct-2022 14:14
26-Oct-2022 01:33
@LiefZimmerman I'm based in europe so I was well awake and coffe-fueled 😉
26-Oct-2022 04:22
@LiefZimmerman to be honest, the Devcentral is an added value when i am looking for solutions, all the creidts goes to @CA_Valli in this case.