Forum Discussion

GeorgeA_32263's avatar
GeorgeA_32263
Icon for Nimbostratus rankNimbostratus
Apr 14, 2014

Redirect URI AND send client browser a custom message

Hello, I have a simple IRule that redirects the URI to a new location. In addition to this, I now want to send an informational message to the client’s browser after the redirect. The message should say something like this: “You are being redirected to a new page, when the redirect is complete, please bookmark the new page” . Is this possible? If yes; could you please give me the correct syntax?

 

when HTTP_REQUEST { if { [HTTP::uri] contains "resources"} { HTTP::redirect "http://www.mywebsite.com/newresources/todaysnews/" }}

 

10 Replies

  • What you are asking for is possible - you need to return (or redirect to) a page which will display your message then redirect to the target page. You web developers should be able to help you with the contents of this page but it would be something along these lines;-

    if { [HTTP::uri] contains "resources"} {        
        HTTP::respond 200 content { Please bookmark the next page}
        return 
    }
    

    Alternatively just use a 301 redirect to the target page which will not show the user a message but should get cached in the users browser. This may be preferable in some ways;-

    if { [HTTP::uri] contains "resources"} {        
        HTTP::respond 301 Location "http://www.mywebsite.com/newresources/todaysnews/" 
        return
    }
    
    • IheartF5_45022's avatar
      IheartF5_45022
      Icon for Nacreous rankNacreous
      Sorry I did try to include the HTML but the goddam filter got me - maybe it will work in a comment? I will try again;- Please bookmark the next page
  • IheartF5:

     

    Thank you helping me. It's greatly appreciated. Am I understanding the 200 code option correctly? The LTM will be returning the message "Please bookmark the next page", and not the IIS server? After the message is delived to the client browser, I must add the syntax to then redirect the client using the syntax below. Is the logic correct? Is the syntax correct?

     

    when HTTP_REQUEST { if { [HTTP::uri] contains "resources"} {

     

    HTTP::respond 200 content { Please bookmark the next page} return }{HTTP::redirect "http://www.mywebsite.com/newresources/todaysnews/" }}

     

  • The LTM will be returning the message "Please bookmark the next page", and not the IIS server?

     

    correct

     

    After the message is delived to the client browser, I must add the syntax to then redirect the client using the syntax below.

     

    one of example is to send html page with meta refresh tag similar to the codeshare below.

     

    LTM Maintenance Page Lite

     

    https://devcentral.f5.com/wiki/iRules.LTMMaintenancePageLite.ashx

     

    • GeorgeA_32263's avatar
      GeorgeA_32263
      Icon for Nimbostratus rankNimbostratus
      Now I understand. This makes sense. I have asked our WEB application group to give me the HTML code for the "message". The maintenance page code is great, I have been useing redirects to maintenance pages for some time, this code will be an improvement. Very grateful for your help. George
  • The LTM will be returning the message "Please bookmark the next page", and not the IIS server?

     

    correct

     

    After the message is delived to the client browser, I must add the syntax to then redirect the client using the syntax below.

     

    one of example is to send html page with meta refresh tag similar to the codeshare below.

     

    LTM Maintenance Page Lite

     

    https://devcentral.f5.com/wiki/iRules.LTMMaintenancePageLite.ashx

     

    • GeorgeA_32263's avatar
      GeorgeA_32263
      Icon for Nimbostratus rankNimbostratus
      Now I understand. This makes sense. I have asked our WEB application group to give me the HTML code for the "message". The maintenance page code is great, I have been useing redirects to maintenance pages for some time, this code will be an improvement. Very grateful for your help. George
  • Sorry; I moved too quickly. Tested the syntax below. The result is:, the browser displays the message "please bookmark the next page" with no problems. don't need the html code. However the execution stops there. the next procedure; to redirect to http://www.mywebsite.com/newresources/todaysnews does not execute. Is it supposed to go to the next line of code after the "return" and execute the redirect or is something missing?

     

    when HTTP_REQUEST { if { [HTTP::uri] contains "resources"} {

     

    HTTP::respond 200 content { Please bookmark the next page} return }{HTTP::redirect "http://www.mywebsite.com/newresources/todaysnews/" }}

     

  • Is it supposed to go to the next line of code after the "return" and execute the redirect or is something missing?

     

    no, return will exit from irule event.

     

    return

     

    https://devcentral.f5.com/wiki/iRules.return.ashx

     

    anyway, you cannot use both HTTP::respond and HTTP::redirect at the same time. just use HTTP::respond similar to the following and remove HTTP::redirect.