Forum Discussion
John_Heyer_1508
Cirrostratus
Jul 13, 2015How to get domain name in iRule?
I have a redirect rule that I need to apply to about 30 different FQDNs:
foo.domain1.com/XYZ -> bar.domain1.com/XYZ
foo.domain2.com/XYZ -> bar.domain2.com/XYZ
foo.domain3.com/XYZ -> bar.domain3....
VernonWells
Employee
Jul 13, 2015Certainly. Firstly, I assume you want to make sure that you match "foo" only when it is the complete name leaf, and outside of that, you will substitute any domain name which contains that leaf:
when HTTP_REQUEST {
if { [HTTP::host] starts_with "foo." } {
HTTP::redirect "https://bar.[string range [HTTP::host] 4 end][HTTP::uri]
}
}
The
4 in the string range command is the length of the leaf name and its following dot (foo., in this example). Notice, as well, that the leading slash (/) is not needed before HTTP::uri (although, strictly speaking, a user-agent could pass the protocol and/or host part in the Request-URI, but that's an entirely different problem).John_Heyer_1508
Cirrostratus
Jul 13, 2015That's another nice solution. Really all depends on what's more readible.
And yes, realized the URI will always start with a / so no need to have an extra one in there.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
