Forum Discussion
URL redirect to another
I am new to the F5 I need to create a simple Irule that redirects one URL to another. here is what I have, that does not work:
when HTTP_REQUEST { if { (([HTTP::host] equals "abc.com/sonar")) } { HTTP::redirect "https://abc.com/sonar/sessions/new?return_to=%2Fsonar%2F" } else {HTTP::redirect https://[HTTP::host][HTTP::uri]} }
But this does not work it only picks up the second condition and redirects http to https. any help would be great.
3 Replies
- nitass
Employee
can you try something like this?
when HTTP_REQUEST { if { [HTTP::host] equals "abc.com" and [HTTP::path] equals "/sonar" } { HTTP::redirect "https://abc.com/sonar/sessions/new?return_to=%2Fsonar%2F" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } - mimlo_61970
Cumulonimbus
HTTP::host will never match abc.com/sonar, it would only match abc.com You need to use HTTP::host to match the host, and HTTP::uri to match the path.
when HTTP_REQUEST { if { (([string tolower [HTTP::host]] equals "abc.com") and ([string tolower [HTTP::uri]] equals "/sonar")) { HTTP::redirect "https://abc.com/sonar/sessions/new?return_to=%2Fsonar%2F" } else { HTTP::redirect https://[HTTP::host][HTTP::uri] }I think that should world. You can also do this with an HTTPClass or policy(depending on your LTM version) instead of an iRule.
- Anthony_1648
Nimbostratus
I need a very similar iRule as the first example, but where the case of /sonar can be either /sonar or /Sonar. I tried the second example, but it does not work. I tried to modify the first one to;
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com" and [HTTP::path] equals "/sonar" } { HTTP::redirect "https://domain.site.com } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
But that doesn't work for me. I would appreciate any help or suggestions.
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