Forum Discussion
SamiK_85475
Jan 09, 2011Nimbostratus
Changing the host name, part of the URI and then redirect
Hello,
I've seen lots of ideas close to what I'm trying to accomplish, but I still seem to run into problems. I hope you can help.
I'm trying catch all http requests, if the host name contains "acb.com" and if the URI starts with "/se", and redirect them to www.xyz.com/sv/orginal_uri_without_/se . Thus /se/"rest of the uri" needs to be replaced with /sv/"rest of the uri".
E.g. any.abc.com/se/pages/index.htm -----> www.xyz.com/sv/pages/index.htm
Here's what I have:
when HTTP_REQUEST {
if { [HTTP::host]} contains "acb.com"
if { [HTTP::uri] starts_with "/se" } {
HTTP::uri "/sv[string range $uri 3 end]"
HTTP::redirect ]
}
}
I'm fairly new with iRules so any help to make this work would be great!
Thanks,
Sami
- Chris_MillerAltostratusI'm fairly new to string map so my apologies if this isn't the right solution.
This will replace any instance of /se with /sv if both the host and uri conditions are met so it should almost certainly be more specific using "range" as you did. I'm going to quick read up on range and will hopefully update it accordingly.when HTTP_REQUEST { if { [string tolower [HTTP::host]] contains "acb.com" } { if { [string tolower [HTTP::uri]] starts_with "/se" } { HTTP::redirect "http://www.xyz.com[string map {/se /sv} [HTTP::uri]]" } } }
- hooleylistCirrostratusstring range might be slightly more efficient and is more exact. The reason that updating the URI with HTTP::uri $newuri and then accessing it with [HTTP::uri] didn't work is that the values for most HTTP:: commands are cached within the same event and event priority.
- SamiK_85475NimbostratusThanks Chris! Will try your code tomorrow. That string map replacement might be enough. However, if you figure out how to make this work with range - awesome.
- hooleylistCirrostratusYou pretty much had it in your first post:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with "acb.com" and [HTTP::uri] starts_with "/se" }{ HTTP::redirect http://www.xyz.com/sv[string range [HTTP::uri] 3 end] } }
- Chris_MillerAltostratusSomething like this Aaron?
when HTTP_REQUEST { if { [string tolower [HTTP::host]] contains "acb.com" } { if { [string tolower [HTTP::uri]] starts_with "/se" } { HTTP::redirect "http://www.xyz.com/sv[string range [HTTP::uri] 3 end]" } } }
- SamiK_85475NimbostratusBTW, if I wanted to HTTP::respond (with 301) instead of HTTP::redirect (is 302), would that be entirely different beast?
- SamiK_85475Nimbostratus
Worked beautifully, thanks!
I'm having another problem now with multible irules, which cause "TCL redirect/respond not allowed" but I'll try first firgure it out by myself.
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