Forum Discussion
Help with iRule redirect
I have a request from our dev team to redirect https://www.ourwebsite.com/agentlanguagelocator to https://www.ourwebsite.com/apex_extprd/f?p=119:1. Dev team would like users to use /agentlanguagelocator since it's easier to remember.
I tried the iRule below but it's not working.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/agentlanguatelocator" } { HTTP::uri "/apex_extprd/f?p=119:1"
} }
Am I missing something? Any help or comment is appreciated.
Richard
Hello Richard,
Based on your iRule, you are not performing a redirect, you are only changing the URI before it is passed to the server. This is completely transparent to the user/browser.
If your Dev team has requested a redirect, it should probably look closer to this:
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] eq "/agentlanguagelocator"} { HTTP::respond 302 Location "/apex_extprd/f?p=[URI::encode 119:1]" } }Notes
- Notice the use of HTTP::respond, this is not required as HTTP::redirect will perform the same function. My preference is to use HTTP::respond so the status code is clear at all times and to any readers of the iRule.
- The match is only for the URI and it's a case-insensitive exact match. Your requirements may vary.
- If the virtual server handles multiple domain names that don't all have this desired behavior, you should include a domain name match as well.
- The Location header is /apex_extprd/f?p=119:1 and not the full URL. This is a relative redirect directing the browser to use the same scheme (e.g. http / https) and domain name as the original request, but redirect to a different path. If you need the whole URL, that should be changed.
- The value of query parameter p is wrapped with URI::encode. This is because the colon is a reserved URI character and may cause problems if not encoded. You may also directly type 119%3A1 which should be the result of using URI::encode and translates to 119:1.
3 Replies
- Vijay_E
Cirrus
Did you use curl to check the response from the F5 ?
curl -IL https://www.ourwebsite.com/agentlanguagelocator Hello Richard,
Based on your iRule, you are not performing a redirect, you are only changing the URI before it is passed to the server. This is completely transparent to the user/browser.
If your Dev team has requested a redirect, it should probably look closer to this:
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] eq "/agentlanguagelocator"} { HTTP::respond 302 Location "/apex_extprd/f?p=[URI::encode 119:1]" } }Notes
- Notice the use of HTTP::respond, this is not required as HTTP::redirect will perform the same function. My preference is to use HTTP::respond so the status code is clear at all times and to any readers of the iRule.
- The match is only for the URI and it's a case-insensitive exact match. Your requirements may vary.
- If the virtual server handles multiple domain names that don't all have this desired behavior, you should include a domain name match as well.
- The Location header is /apex_extprd/f?p=119:1 and not the full URL. This is a relative redirect directing the browser to use the same scheme (e.g. http / https) and domain name as the original request, but redirect to a different path. If you need the whole URL, that should be changed.
- The value of query parameter p is wrapped with URI::encode. This is because the colon is a reserved URI character and may cause problems if not encoded. You may also directly type 119%3A1 which should be the result of using URI::encode and translates to 119:1.
- Richard_77286
Nimbostratus
Hi Jeremy, Thank you for your response! You are correct, it's not a redirect. It's like creating an alias. The rule you provided above worked. And thank you for taking the time in writing the notes on the rule. Thanks again!
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