Forum Discussion
Help cleaning up IRule redirect with URI rewrite.
So, right up front, I'm an old router guy, so scripting is not my forte. The request is to have requests that come into a VIP be redirected to another URL, change the URI, but maintain all the query information that follows... so, built a datagroup because since these are going to become more common, but this leads to a problem.
5 Replies
- hoolio
Cirrostratus
Hi Cameron,
I understand redirecting old.host.name/abc to new.hostname.name/def. But why are you trying to redirect new.host.name/def back to /abc?
Aaron
Well, not really, and that's the part that I need some help with. The second lookup is used to cut out the part of the original URI that I want to remove.So, from the original uri /abc?xxxxxxx I want to remove just /abc and replace it with new.hostname.name/def. The problem that I'm running into is getting a way to match just the /abc from the original call.
I've put some comments in below to show what I'm trying to do so that you guys can tell the right way to do it.
Thanks all,
Cameron
IRule:
when HTTP_REQUEST {
set urlredir [class match -value [HTTP::uri] starts_with DATA-GROUP]
[HTTP::uri] = old.host.name/abc?xxxxxxxxx
urlredir = new.host.name/def
if { $urlredir ne "" }{
set replace [class match -value $urlredir starts_with DATA-GROUP]
replace = old.host.name/abc without any of the passed arguments.
set redir [string map "$replace $urlredir" [HTTP::uri] ]
redir = the original uri where /abc is replaced with new.host.name/def
and become new.host.name/def?xxxxxxx
HTTP::redirect ""
then redirected.
}
}
Data external group:
"/abc" : = "new.host.name/def",
"new.host.name/def" : = "/abc",- Michael_Yates
Nimbostratus
It looks to me like you are trying to capture the HTTP::query and then verify the HTTP::path ends with your Data Group Value.
Example: www.website.com/abc?value=100
HTTP::uri = /abc?value=100 (Includes "/")
HTTP::path = /abc (Includes "/")
HTTP::query = value=100 (Does not include "?")
You should try setting a variable to capture the query and then compare the path. Then redirect to the next destination and append the HTTP::query. - Michael, that is exactly what I needed. Thanks very much.
Cameron - PeterC_70986
Nimbostratus
Hi cdougall, so what did you end up writing for your irule? I am trying to do this same thing. oldhost.domain.com/abc/ redirect to newhost.domain.com/def/
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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