Forum Discussion

Sergio_Magra's avatar
Sergio_Magra
Icon for Nimbostratus rankNimbostratus
Oct 08, 2013

URI based redirect

Hi all,

    We need to make a redirection based on certain URI, but it does not work due to be incompleted. We made an iRule for this.

    We need that if we receive the following URI:

http://testsite/index.xml!somepage.html

    The redirection sends to:

https://testsite/index.xml!somepage.html

   But after applying the iRule, the browser is redirected to: 

https://testsite/somepage.html

     The iRule looks that the following:
                                                                                                                           when HTTP_REQUEST {
 if { [HTTP::path] ends_with "somepage.html" }{
      log local0.alert "https://[HTTP::host][HTTP::uri]” 
      HTTP::redirect “https://[HTTP::host][HTTP::uri]”
 }

}

What I'm doing wrong?

Thanks and best regards

Sergio

5 Replies

  • your rule is redirecting to the requested host/uri from the client.

     

    try... when HTTP_REQUEST { if { [HTTP::uri] ends_with "somepage.html" }{ log local0.alert "https://[HTTP::host][HTTP::uri]” HTTP::redirect “https://[HTTP::host]/newuri.html” }

     

  • Hi,

    thanks for the answer.
    

    The problem that I see is that the portion of the URI index.xml! is not passed to the HTTP::URI statement. It only passes the value /somepage.html as the URI.

    I will wait for your comments
    

    Thanks and Best regards

  • Using an encoded URI helps to solve the problem. Here is the PoC:

    when HTTP_REQUEST {
        log local0. "[URI::decode [HTTP::uri]]"
        HTTP::redirect http://10.131.131.120/index.xml%23!somepage.html
    }
    

    Now the log fills up with:

    Oct  8 21:49:06 bigip_a11 info tmm[8327]: Rule /Common/rule_redirect : /index.xml!somepage.html
    Oct  8 21:49:06 bigip_a11 info tmm[8327]: Rule /Common/rule_redirect : /index.xml!somepage.html
    
  • The best way to do what you are wanting is as follows:

    when HTTP_REQUEST {  
    
             set host [HTTP::host]  
    
             set uri [HTTP::uri]  
    
         switch -glob [HTTP::path] {  
    
          "somepage.html" {  
    
             HTTP::respond 302 Location "https://$host$uri"
    
             )  
    
               default {  
    
               }  
    
            }  
    
         }    
    
  • Hi,

     

    first of all thanks for everyone who helped me.

     

    Let me say that the real problem is that the variable [HTTP::uri] takes only the end of the URI (/somepage.html) instead of the entire URI (/index.xml!somepage.html).

     

    Also, if you see, it adds a / before somepage.html, while in the original request, it does not ahve any / before somepage.html.

     

    Did you experience a similar behavior?

     

    Thanks in advance

     

    Best regards