Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

iRule for uri redrect

Would you mind please verify below iRule for redirecting the traffic which is going to "/career " redirect to https://jobs.abcd.com

if { [HTTP::uri] equals "/careers" } { HTTP::redirect "https://jobs.abcd.com"; }

Does it work?

Any help with this will be greatly appreciated..!!

Thank you..!!

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Issue got fixed with below iRule.

when HTTP_REQUEST { if { [HTTP::uri] equals "/careers" } {
HTTP::respond 301 Location "https://abc.com";;
} }

Thank you Stanislas for all your support..!!

Regards, Mohan

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

I should recommend to do it with a policy instead of irule!

Your code may work but I would recommend to :

Filter on HTTP::path instead of HTTP::uri

Use starts_with instead of equals if you want to catch all subdirectories of /careers

0
Comments on this Answer
Comment made 20-Jun-2018 by Mohan.Kumar 18

Thank you for the immediate response Stanislas, so just to make sure below is the irule with the correction of what you recommend. I never done via policy, would you be able to walk me through?

if { [HTTP::path] starts_with "/careers" } { HTTP::redirect "https://jobs.abcd.com";; }

Would that work?

0
Comment made 21-Jun-2018 by Stanislas Piron 10623

This code may work in an irule

when HTTP_REQUEST {
    if { [HTTP::path] starts_with "/careers" } {     
        HTTP::redirect "https://jobs.abcd.com";;         
    }
}

With a policy, create a new policy with one rule

  • Condition
    http-uri path begins with /careers
  • action
    Http-reply redirect https://....
0
Comment made 21-Jun-2018 by Mohan.Kumar 18

Awesome..!! I'll test and let you know Stanislas. Truly appreciated your immediate response..!!

0
Comment made 21-Jun-2018 by Mohan.Kumar 18

Image Text

Here is the screenshot of the policy before i publish to verify.

Thanks Again..!!

0
Comment made 21-Jun-2018 by Mohan.Kumar 18

Stanislas,

When we tried with policy, it is sending a 302 redirect (which is temporary move) as opposed to 301 redirect (which is permanent move). Unfortunately, we need 301.

Is there a way to do 301 redirect using Policy?

Any help much appreciated..!!

Thank you..!!

0
Comment made 25-Jun-2018 by swjo 311

Hi Stanislas.

I have question regarding i-rule syntax.

what`s different [HTTP::path] and [HTTP::host][HTTP::uri]

I usually use like this.

when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "image.abc.com" } { pool p_image_down_[TCP::local_port] } elseif { [string tolower [HTTP::host]] equals "prev.abc.com" } { pool p_prev_[TCP::local_port] log local0. " [IP::client_addr] access [IP::local_addr]:[TCP::local_port] request [HTTP::host][HTTP::uri] " }

0
Comment made 25-Jun-2018 by Stanislas Piron 10623

In URL https://www.company.com/login.php?user=me&password=whatever

  • [HTTP::host] returns www.company.com
  • [HTTP::uri] returns /login.php?user=me&password=whatever
  • [HTTP::path] returns /login.php
  • [HTTP::host][HTTP::uri] concatenate both [HTTP::host] and [HTTP::uri]
0