Forum Discussion
Help with iRule redirect
- Mar 18, 2017
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.
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_77286Mar 21, 2017Nimbostratus
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!
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