Forum Discussion
URI iRule Redirect Question
Hello,
I have the below customer request. I was wondering if the below iRule would handle the request properly. If it looks good I'll try it out on Monday. If you have any suggestions, please feel free to make them. I'm just getting into using iRule URI redirects. I have done a few URL redirects successfully.
Customer Request: Redirect www.website.com/points to points.website.com along with all query parameters.
MY NOTE: The query parameters they speak of should contain POINTS, or another I'll call, ABCD in the URI. Are these case sensitive in the iRule? I created the below proposed iRule for this request.
when HTTP_REQUEST { set uri [HTTP::uri] if { ($uri contains "points")} then { HTTP::respond 301 Location "https://points.website.com/"} elseif { ($uri contains "abcd")} then { HTTP::respond 301 Location "https://points.website.com/"}}
9 Replies
- Cory_50405
Noctilucent
Try this one:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd") } { HTTP::respond 301 Location "https://points.website.com/" } } - What_Lies_Bene1
Cirrostratus
I think mski wanted to maintain the query portion of the request too;
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd") } { HTTP::redirect "https://points.website.com/[HTTP::query]" } } - Cory_50405
Noctilucent
This should do you, as HTTP::uri contains the query portion as well:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd") } { HTTP::redirect "https://points.website.com/[HTTP::uri]" } }- mski_151743
Nimbostratus
Thanks! That seems to be working from my perspective. I will have the customer test tomorrow to verify. It may take a few days, but I'll report back with the results. I really appreciate it! - Cory_50405
Noctilucent
Good to hear.
- nitass
Employee
shouldn't it be HTTP::query in HTTP::redirect (rather than HTTP::uri)?
HTTP::query
https://devcentral.f5.com/wiki/iRules.http__query.ashxe.g.
[root@ve11a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd" } { HTTP::redirect "https://points.website.com/?[HTTP::query]" } } } [root@ve11a:Active:In Sync] config curl -I http://www.website.com/points?icid=ABCD_PROMO_POINTS HTTP/1.0 302 Found Location: https://points.website.com/?icid=ABCD_PROMO_POINTS Server: BigIP Connection: Keep-Alive Content-Length: 0- mski_151743
Nimbostratus
I was able to use all the iRule suggestions to come up with the below iRule to get the query redirect working. The customer is satisfied. I'm happy it works and happy that I learned a bit more about this type of iRule. Thanks again! when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" } { HTTP::redirect "https://points.website.com?[HTTP::query]" } }
- nitass_89166
Noctilucent
shouldn't it be HTTP::query in HTTP::redirect (rather than HTTP::uri)?
HTTP::query
https://devcentral.f5.com/wiki/iRules.http__query.ashxe.g.
[root@ve11a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd" } { HTTP::redirect "https://points.website.com/?[HTTP::query]" } } } [root@ve11a:Active:In Sync] config curl -I http://www.website.com/points?icid=ABCD_PROMO_POINTS HTTP/1.0 302 Found Location: https://points.website.com/?icid=ABCD_PROMO_POINTS Server: BigIP Connection: Keep-Alive Content-Length: 0- mski_151743
Nimbostratus
I was able to use all the iRule suggestions to come up with the below iRule to get the query redirect working. The customer is satisfied. I'm happy it works and happy that I learned a bit more about this type of iRule. Thanks again! when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" } { HTTP::redirect "https://points.website.com?[HTTP::query]" } }
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