Forum Discussion

ivanchen0503_36's avatar
ivanchen0503_36
Icon for Nimbostratus rankNimbostratus
Mar 29, 2019

iRule how to use rewrite by same token ?

Im not sure about F5 iRule can or not solve this solution , i need rewrite to , only rewrite "iphone.aspx" to "mobile" this key point and the token number need same .. anyone can help this ? thanks .

 

2 Replies

  • Yeah you can do with irule. Try below..

        when HTTP_REQUEST { 
          set id [URI::query [HTTP::uri] token]
          if { [HTTP::uri] starts_with "/iphone.aspx" } {
          HTTP::redirect "https://www.abc.com/mobile?token=$id"
            } 
        }
    
  • Do you want to rewrite or redirect?

    For a rewrite:

    when HTTP_REQUEST { 
      if { [HTTP::path] equals "/iphone.aspx" } {
      HTTP::path "/mobile"
        } 
    }    
    

    For a redirect

    when HTTP_REQUEST { 
      if { [HTTP::path] equals "/iphone.aspx" } {
      HTTP::redirect [join [list "/mobile" [HTTP::query]] "?" ]
        } 
    }        
    

    Join command is there to add question mark only if query string is not empty