Forum Discussion
Pav_70755
Sep 20, 2011Nimbostratus
HTTP Re-Direct uri replace?
I have the following rule written
when HTTP_REQUEST {
if { [HTTP::uri] contains "?storyId=" } {
pool STAGE_directmarketing.thomsonnet.co.uk-80
}
elseif { [HTTP::uri] starts_with "/win" or [HTTP::uri] starts_with "/Win" }{
HTTP::redirect "http://www.news.com/Marketing-Services/"
}
elseif { [HTTP::uri] ends_with "/talk" } {
HTTP::redirect "http://www.news.com/Marketing-Services/"
}
elseif { [HTTP::uri] ends_with "/find" } {
HTTP::redirect "http://www.news.com/Business-Data/"
} else {
pool STAGE_www.news.com-80
}
}
And what I've been asked to do is the following:
anything with "/win" in the uri to replace it with "/News-Advice/
e.g if someone has the following url bookmarked
www.news.com/win/News-Archive it should go to
www.news.com/News-Advice/News-Archive
any help would be much apprecaited.
Thanks
Pav
- Brian_69413NimbostratusA couple things:
- Pav_70755NimbostratusHi Brian,
when HTTP_REQUEST { set extracta [URI::query [HTTP::query] "New-Advice" ] if { [HTTP::uri] ends_with "/win" } { HTTP::redirect "http://www.new.com/$extracta" }} elseif { [HTTP::uri] ends_with "/talk" } { HTTP::redirect "http://www.news.comk/Marketing-Services/" } elseif { [HTTP::uri] ends_with "/find" } { HTTP::redirect "http://www.news.comk/Business-Data/" } else { pool STAGE_www.news.com-80 } }
- Brian_69413NimbostratusI think you would do the following:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/win" } { set extracta [substr [HTTP::uri] "/win" ""] HTTP::redirect "http://www.new.com/New-Advice$extracta" } elseif { [HTTP::uri] ends_with "/talk" } { HTTP::redirect "http://www.news.comk/Marketing-Services/" } elseif { [HTTP::uri] ends_with "/find" } { HTTP::redirect "http://www.news.comk/Business-Data/" } else { pool STAGE_www.news.com-80 } }
- Pav_70755NimbostratusThanks Brian I'm getting the following error with that rule:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/win" } { set wininsert [substr [HTTP::uri] "/win" ""] HTTP::redirect "http://www.new.com/New-Advice$wininsert" } elseif { [HTTP::uri] starts_with "/talk" } { set talkinsert [substr [HTTP::uri] "/talk" ""] HTTP::redirect "http://www.new.com/Marketing-Services$talkinsert" } elseif { [HTTP::uri] starts_with "/find" } { set findinsert [substr [HTTP::uri] "/find" ""] HTTP::redirect "http://www.new.com/New-Advice$findinsert" } else { pool STAGE_www.news.com-80 } }
- Brian_69413NimbostratusNot sure why substr is not working...you could also try a string trimleft since you know exactly what the values are. Replace the substr lines with these:
set wininsert string trimleft [HTTP::uri] 4 set talkinsert string trimleft [HTTP::uri] 5 set findinsert string trimleft [HTTP::uri] 5
- Pav_70755NimbostratusThanks Brian i'm getting the following error:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/win" } { set wininsert string trimleft [HTTP::uri] 4 HTTP::redirect "http://www.new.com/New-Advice$wininsert" } elseif { [HTTP::uri] starts_with "/talk" } { set talkinsert string trimleft [HTTP::uri] 5 HTTP::redirect "http://www.new.com/New-Advice$talkinsert" } elseif { [HTTP::uri] starts_with "/find" } { set findinsert string trimleft [HTTP::uri] 5 HTTP::redirect "http://www.new.com/New-Advice$findinsert" } else { pool STAGE_www.new.com-80 } }
- Brian_69413NimbostratusYou probably have to enclose the actual function in square brackets:
set wininsert [string trimleft [HTTP::uri] 4]
- Pav_70755NimbostratusThanks Brian i'm still learning when it comes to Irules as you can see! so whats the timleft argument doing?
- Brian_69413NimbostratusWow, I completely misinterpreted string trimleft. I thought the chars variable was an integer of how many characters you wanted to trim from the left, but instead, it is a list of characters that you want to match, so it would be something like this:
set wininsert [string trimleft [HTTP::uri] /win]
- Brian_69413NimbostratusI tested this one and it works...maybe someone can come up with something better:
set wininsert [string range [HTTP::uri] 4 end] set talkinsert [string range [HTTP::uri] 5 end] set findinsert [string range [HTTP::uri] 5 end]
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