For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

PowerRangers's avatar
PowerRangers
Icon for Cirrostratus rankCirrostratus
Jan 19, 2023
Solved

Need to redirect complete URL into redirected uri

  • Paulius's avatar
    Paulius
    Jan 19, 2023

    PowerRangers If your intent is to redirect anything going to www.abc.com  with any URI path starting with "/find/redirect/" the following should work for you.

     

    when CLIENT_ACCEPTED priority 500 {
    
        set DEFAULT_POOL [LB::server pool]
    
    }
    
    when HTTP_REQUEST priority 500 {
    
        set HOST [string tolower [HTTP::host]]
        set URI [string tolower [HTTP::uri]]
    
        if { ${HOST} == "www.abc.com" } {
            if { ${URI} starts_with "/find/redirect/" } {
                
                HTTP::respond 301 Location "https://www.xyz.com/found/redirect?url=https://$HOST$URI"
    
            }
        } else {
            $DEFAULT_POOL
        }
    
    }

     

    Now if you want to redirect anything that connects to www.abc.com  to www.xyz.com/found/redirect?url=https:// <old_path> the following should do the job.

     

    when CLIENT_ACCEPTED priority 500 {
    
        set DEFAULT_POOL [LB::server pool]
    
    }
    
    when HTTP_REQUEST priority 500 {
    
        set HOST [string tolower [HTTP::host]]
        set URI [string tolower [HTTP::uri]]
    
        if { ${HOST} == "www.abc.com" } {
    
            HTTP::respond 301 Location "https://www.xyz.com/found/redirect?url=https://$HOST$URI"
    
        } else {
            $DEFAULT_POOL
        }
    
    }

     

    If I am missunderstanding the request please provide a real world example of one of the requests or rewording the question so we can have a different approach to the issue at hand.

4 Replies

  • PowerRangers I believe something like the following would work for you while also assuming your virtual server has a default pool associated to it and you are performing SSL termination on that virtual server.

    when CLIENT_ACCEPTED priority 500 {
    
        set DEFAULT_POOL [LB::server pool]
    
    }
    
    when HTTP_REQUEST priority 500 {
    
        set HOST [string tolower [HTTP::host]]
        set URI [string tolower [HTTP::uri]]
    
        if { ${HOST} == "www.abc.com" } {
            if { ${URI} == "/find/redirect" } {
                
                HTTP::respond 301 Location "https://www.xyz.com/found/redirect?url=https://$HOST$URI"
    
            }
        } else {
            $DEFAULT_POOL
        }
    
    }

     

  • Hello Paulius,

    Thank you for the rule, I see its working with the URI only when its "/find/redirect". 

    it is not working when I use "*"  if { ${URI} == "/find/redirect/*" } 

    i tried starts with but syntax error. How to ger all the query string in path which starts with /find/redirect/XXXX/xXXx/XXX/XX something like this.

    Appreciate your help.

     

    • Paulius's avatar
      Paulius
      Icon for MVP rankMVP

      PowerRangers If your intent is to redirect anything going to www.abc.com  with any URI path starting with "/find/redirect/" the following should work for you.

       

      when CLIENT_ACCEPTED priority 500 {
      
          set DEFAULT_POOL [LB::server pool]
      
      }
      
      when HTTP_REQUEST priority 500 {
      
          set HOST [string tolower [HTTP::host]]
          set URI [string tolower [HTTP::uri]]
      
          if { ${HOST} == "www.abc.com" } {
              if { ${URI} starts_with "/find/redirect/" } {
                  
                  HTTP::respond 301 Location "https://www.xyz.com/found/redirect?url=https://$HOST$URI"
      
              }
          } else {
              $DEFAULT_POOL
          }
      
      }

       

      Now if you want to redirect anything that connects to www.abc.com  to www.xyz.com/found/redirect?url=https:// <old_path> the following should do the job.

       

      when CLIENT_ACCEPTED priority 500 {
      
          set DEFAULT_POOL [LB::server pool]
      
      }
      
      when HTTP_REQUEST priority 500 {
      
          set HOST [string tolower [HTTP::host]]
          set URI [string tolower [HTTP::uri]]
      
          if { ${HOST} == "www.abc.com" } {
      
              HTTP::respond 301 Location "https://www.xyz.com/found/redirect?url=https://$HOST$URI"
      
          } else {
              $DEFAULT_POOL
          }
      
      }

       

      If I am missunderstanding the request please provide a real world example of one of the requests or rewording the question so we can have a different approach to the issue at hand.

  • Hello Paulius, 

    I see its working now thanks you so much again. 😄 

    Starts_with worked. 🙂