redirect URL iRule

Hello

I want to an iRule to redirect

http://anything.com/abc to http://something.com/abc

such a short question…

What do you mean by “redirect”? Most of question with redirect on this forum is forward and not redirect…

If you look some question below, you can find this question with the same need: DevCentral - An F5 Technical Community

did you look the link??? your need is covered by it…

you can also create a LTM policy instead of iRule if you don’t know how to manage irules…

Create a policy with require “http” and action “Forward”.

Create a rule with

  • condition HTTP Host equals anything.com
  • action http reply redirect location http://[HTTP::host][HTTP::host]

Apply the policy in VS ressources… and finished…

can you upload your policy screenshot?

your condition and action are wrong..

  • condition : http-host host equals tstwsl.cio.gov.bh
  • action : http reply redirect location http://vtstwsl.cio.gov.bh[HTTP::host]

why did you configure http-auth condition???

I want to add that for http://something.com there are no virtual servers were created i have 2 virtual servers HTTP and HTTPs for http://anything.com

did you assign this policy on the VS configuration?

what behavior do you have?

Hi Ahmad, to make it short- remove the policy from VS and apply below irule to VS and try please

when HTTP_REQUEST {
    if { ([HTTP::host] contains "tstwsl.cio.gov.bh") } {
        HTTP::redirect "http://vtstwsl.cio.gov.bh[HTTP::uri]" }
 }

This is the iRule solution which do the same as my policy… except…

  • policy condition is not case sensitive by default… irule is… we need to use string tolower to compare lowercase strings..
  • you specify “contains” in condition, i choose “equals”

When a question is like this one, I think the policies are easier than irules to understand and configure…

Most of my deployments use both irules and policies:

  • policies to manage URL-based rules (redirects, pool assignments header replace, define tcl variables to be used by irules executed after) and rules with source IPs conditions (since 11.6)
  • irules to manage complexe needs…

The main goal of this is when changing irules, there is a risk of TCL error if something is wrong… so when there is a new need for a specific URL, the administrator can modify the policy easily and safer.

Ahmad,

The provided irule and policy may work.

I think the issue is these configuration are not applied to the VS. can you upload your VS configuration?

to get configuration of a virtual server, connect to SSH and execute :

tmsh list ltm virtual

change your IP information and upload it.

Any Update ?

Any Update ?

Thank you for your help the issue has been solved it was network issue…

thank you again