Forum Discussion
neeraj_66310
Nimbostratus
Dec 13, 2007I need to remove host from url and send it to particular pool
I am novice for creating irule, Kindly help me out for below requirement:--
user make request for one of 3 urls as below:--
1)http://main.test.com
2)http://main.test.com/first.test...
Dec 13, 2007
Glad to be of help. Just to let you know that we are not consulting here at DevCentral and would like to see our users put some effort in writing the iRules themselves to help you all be more self-sufficient. We are here to help out debugging and giving you guidance (and occasionally write functional iRules when the need arises).
I know this is hard for someone who is new to the technology and we do our best to help out in these situations so hopefully my first stab got you going in the right direction. I'd really like you to try to do this yourself. I'll line out what and how you need to do it and then you can give it a try. After you do and you are still having issues, please post your iRule and we'll work through it together. This way you, as well as the rest of the community, will benefit.
Take my above iRule:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/first.test.com*" {
HTTP::header replace "Host" "first.test.com"
HTTP::uri "/"
pool pool_first
}
"/second.test.com*" {
HTTP::header replace "Host" "second.test.com"
HTTP::uri "/"
pool pool_second
}
default {
pool poolmain
}
}
}
The conditional testing is there already which you have determined is correct. In this code, I've replace the "Host" header with the pulled out values from the URIs and you've said that part is correct. So, the last part is removing the new host value from the URI. You can easily do this with the "string map" command.
Here's an example of replacing a string with string map:
set orig "/one/two/three/four"
set stripped [string map { "/two" "" } $orig]
In the above code the value of the $stripped variable will contain the value of $orig with all matches of "/two" replaced with "" (essentially removing it from the string). The value of $stripped will be "/one/three/four"
Taking this in your example, you'll what to do something like this for each of your matched cases
HTTP::uri [string map { "somval" "" } [HTTP::uri]]
Replace "someval" with the string you want to remove and this command will use the assignment version of the HTTP::uri command and assign it the value of the HTTP URI with "someval" stripped. In your case use "/first.test.com", "second.test.com", etc.
Give this a shot and post back when you've fixed the iRule and it still doesn't seem to be working.
Cheers!
-Joe
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