Forum Discussion
Rewrite Subdomain
- Oct 17, 2022
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
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
- CA_ValliOct 17, 2022MVP
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
- MuhannadOct 19, 2022Cirrus
This is working perfectly thanks :).
- LiefZimmermanOct 25, 2022Admin
"Working perfectly!" so good.
And...if I'm reading this right... CA_Valli - you had this solution in place only 2hrs after Muhannad asked? and in the middle of the night (for me on the west coast of US)?
Thank you for your perfection & speed!
⏩🚀- CA_ValliOct 26, 2022MVP
LiefZimmerman I'm based in europe so I was well awake and coffe-fueled 😉
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