Forum Discussion
URI based redirect
Hi all,
We need to make a redirection based on certain URI, but it does not work due to be incompleted. We made an iRule for this.
We need that if we receive the following URI:
http://testsite/index.xml!somepage.html
The redirection sends to:
https://testsite/index.xml!somepage.html
But after applying the iRule, the browser is redirected to:
https://testsite/somepage.html
The iRule looks that the following:
when HTTP_REQUEST {
if { [HTTP::path] ends_with "somepage.html" }{
log local0.alert "https://[HTTP::host][HTTP::uri]”
HTTP::redirect “https://[HTTP::host][HTTP::uri]”
}
}
What I'm doing wrong?
Thanks and best regards
Sergio
5 Replies
- bboyjnr_8532
Cirrus
your rule is redirecting to the requested host/uri from the client.
try... when HTTP_REQUEST { if { [HTTP::uri] ends_with "somepage.html" }{ log local0.alert "https://[HTTP::host][HTTP::uri]” HTTP::redirect “https://[HTTP::host]/newuri.html” }
- Sergio_Magra
Nimbostratus
Hi,
thanks for the answer.The problem that I see is that the portion of the URI index.xml! is not passed to the HTTP::URI statement. It only passes the value /somepage.html as the URI.
I will wait for your commentsThanks and Best regards
- StephanManthey
Nacreous
Using an encoded URI helps to solve the problem. Here is the PoC:
when HTTP_REQUEST { log local0. "[URI::decode [HTTP::uri]]" HTTP::redirect http://10.131.131.120/index.xml%23!somepage.html }Now the log fills up with:
Oct 8 21:49:06 bigip_a11 info tmm[8327]: Rule /Common/rule_redirect : /index.xml!somepage.html Oct 8 21:49:06 bigip_a11 info tmm[8327]: Rule /Common/rule_redirect : /index.xml!somepage.html - David_123674
Nimbostratus
The best way to do what you are wanting is as follows:
when HTTP_REQUEST { set host [HTTP::host] set uri [HTTP::uri] switch -glob [HTTP::path] { "somepage.html" { HTTP::respond 302 Location "https://$host$uri" ) default { } } } - Sergio_Magra
Nimbostratus
Hi,
first of all thanks for everyone who helped me.
Let me say that the real problem is that the variable [HTTP::uri] takes only the end of the URI (/somepage.html) instead of the entire URI (/index.xml!somepage.html).
Also, if you see, it adds a / before somepage.html, while in the original request, it does not ahve any / before somepage.html.
Did you experience a similar behavior?
Thanks in advance
Best regards
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