Forum Discussion
Standard irule that can be used for multiple urls
Thank you CA_Valli.
I think this works when we are hardcoding the app1 in the condition.
I was wondering if this irule can be agnostic in a way it can be used for any number of Virtual servers.
Example:
testurl.externaldomain.com/app1/api/hello
testurl.extenaldomain.com/app2/api/bye
testdifferenturl.externaldomain.com/app4/api/test/*/*
so all these urls will have one virutal server which should have a common generalized irule.
testurl.externaldomain.com/app1dev/api/hello - it would be a redirect the customer still sees the same url in the browser.
set hostname: app1dev.internaldomain.com/api/hello
set pool : testurl.externaldomain.com_app1dev
testurl.externaldomain.com/app1qa/api/getemployeedetails - it would be a redirect the customer still sees the same url in the browser.
set hostname: app1qa.internaldomain.com/api/getemployeedetails
set pool : testurl.externaldomain.com_app1qa
the way we formulated the url is
externaldomain/appname/whateverapitheappsupports.
appname needs to be appended with internaldomain and the whateverapitheappsupports need to the URI.
whateverapitheappsupports - this can be just /api/hello or /api/employee/1234 or /swagger anything that comes after the app name.
Please let me know if the above example is clear or if i am not explaining it properly.
It's possible, indeed.
I'm struggling a bit to see the logic you want to implement based on naming conventions, I've developed the following, feel free to adjust it as you require.
when HTTP_REQUEST {
set hostname [string tolower [HTTP::host]]
#This IF exists to implement hostname exclusion
# if {[class match $hostname eq datagroup_irule_exlcusion]}{ return }
set uri [HTTP::uri]
set poolname "testurl.externaldomain.com_"
set newhost ".internaldomain.com"
set application [substr $uri 1 "/"] ; log local0. "application is $application"
set newuri [string trimleft $uri "/$application"]
set poolname "$poolname$application" ; log local0. "pool $poolname"
set newhost "$application$newhost" ; log local0. "host $newhost"
# do you need a redirect (1), or a rewrite (2)?
# (1) client will see the redirect
# HTTP::redirect "http://$newhost/$newuri"
# (2) rewrite is transparent to client
# HTTP::header replace "Host" "$newhost"
# HTTP::uri "$newuri"
# pool $poolname
}
With redirect instruction, client sees this. As you can see URL was changed to new host and URI is cropped and retained.
LTM logs:
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