Forum Discussion

Tyron_Fourie_18's avatar
Oct 29, 2015

Redirect URL

Hi,

 

I am looking to redirect http://www.examplesite.com/Examplepage.html to an external site like http://www.externalsite.com/

 

As I understand it there are multiple ways to do this so I have 2 questions about it.

 

  1. Which is the best way to do this?
  2. Which is the easiest way to do this?

I have tried multiple methods in doing this and have failed each time. Namely:

 

  1. https://devcentral.f5.com/questions/simple-url-redirect-irule
  2. https://devcentral.f5.com/questions/irule-for-http-redirect-from-retired-url-to-new-url
  3. Redirect Policies
  4. Rewrite Service

Thanks in advanced.

 

  • I had a similar situation. What i did was: * create a pool with no active members * create a VS and assign this pool to it * create an irule which looked at the of active members in the pool and if is 0 then redirect to external URL The irule is as below:

     

    when HTTP_REQUEST { if { [active_members TS-EmptyPool] == 0 }{ HTTP::redirect "https://www.surveymonkey.com/s/eg.survey" } }

     

    karthik

     

  • Assuming the virtual only hosts a single domain

    when HTTP_REQUEST {
        if {[string tolower [HTTP::path]] eq "/examplepage.html"} {
           HTTP::respond 301 noserver Location "http://www.externalsite.com/"
           return
        }
    }
    

    Otherwise if www.examplesite.com is a vhost on the virtual try this;-

    when HTTP_REQUEST {
        if {[string tolower [HTTP::path]] eq "/examplepage.html" && [getfield [HTTP::host] : 1] eq "www.examplesite.com"} {
           HTTP::respond 301 noserver Location "http://www.externalsite.com/"
           return
        }
    }
    

    Now as to what's best/easiest....it's a matter of personal taste really. For me an iRule is easiest, however in theory a Local Traffic Policy or Rewrite Service is more efficient. Try them all and see what suits you....

    Let me know if the iRule doesn't work for you.....

  • if you want to redirect to two diffent pools based on path? How the irule change?

     

    Thanks for your help

     

  • I had a similar situation. What i did was: * create a pool with no active members * create a VS and assign this pool to it * create an irule which looked at the of active members in the pool and if is 0 then redirect to external URL The irule is as below:

     

    when HTTP_REQUEST { if { [active_members TS-EmptyPool] == 0 }{ HTTP::redirect "https://www.surveymonkey.com/s/eg.survey" } }

     

    karthik