Forum Discussion
dundovic_25174
Nimbostratus
Jan 23, 2012HTTP Class profile redirect
I understand this is iRule discussion forum and I can achieve this using iRule, but due to some specific customer requirements, they'd like to have it done using 'HTTP class' profile.
Following should explain the task.
Original URL:
http://Server1.domain1.com/Folder1/
Redirect to:
http://Server2.domain2.com/Folder2/
Basically, any request coming to 'server1' and 'Folder1' should be redirected to 'Server2'/'Folder2', but the rest of path should be retained. Could this be achieved using 'HTTP class' profile?
Thanks!
9 Replies
- dundovic_25174
Nimbostratus
Seems like the rest of the path was removed...it should read:
Original URL:
http://Server1.domain1.com/Folder1/REST_OF_PATH
Redirect to:
http://Server2.domain2.com/Folder2/REST_OF_PATH - George_Watkins_Historic F5 AccountHere is the config I used (output from tmsh):
test-ltm-ve-03(Active)(/Common)(tmos) list ltm profile httpclass redirect_server1_to_server2ltm profile httpclass redirect_server1_to_server2 {
app-service none
defaults-from httpclass
hosts { glob:Server1.domain1.com }
paths { glob:/Folder1 }
pool none
redirect http://Server2.domain2.com/Folder2/
}
Keep in mind that the matches are case sensitive, so if you are expecting different capitalization, you might want to use a regex (slower). Hope that helps,
-George
- George_Watkins_Historic F5 AccountHi dundovic,
I don't think you can use regex matches within HTTP class profiles. If you want match and replace, you'll have to use an iRule here.
-George - dundovic_25174
Nimbostratus
Thanks for your suggestions, George. I'll try to find out if HTTP class can be somehow used in this scenario, otherwise, I'll have to proceed with an iRule, which was my original idea.
Regards,
S. - hoolio
Cirrostratus
As Michael showed, you can use iRule commands in the Redirect to Location field. So you can append the current URI using [HTTP::uri]. If you want to substitute a string (Folder1) for another (Folder2) within the URI, you could use:
http://server2.domain3.com[string map {Folder1 Folder2} [HTTP::uri]]
Aaron - dundovic_25174
Nimbostratus
Thanks all! I appreciate your help. I didn't know iRule commands could be mixed with the field entries.
Regards,
S. - George_Watkins_Historic F5 AccountAwesome! Thanks Michael and hoolio. I learned something today!
- CurtisBates_289
Nimbostratus
How would you use the Headers -> Header List to redirect based on the value of a header? How do you specify the header and the expected value? Can you write: X-Roles="admin", for example, as a matching condition? I'm not sure I understand the intent of headers in the HTTP Class Profile dialog pictured above.
Thanks! - hoolio
Cirrostratus
Hi Curtis,
The header field of an HTTP class is checked against each HTTP header line. If you want to match just a header name, you could set the Headers field to "header-name:" without the quotes. If you want to match a specific header name and value, you can set the Headers field to "header-name: header-value" without the quotes. If you want to perform a case-insensitive match, you can use a regex instead of a string pattern and use the (?i) token:
(?i)header-name: header-value
Aaron
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
