Forum Discussion

Korai_331784's avatar
Korai_331784
Icon for Altostratus rankAltostratus
May 31, 2018

Redirection of one site to another

Hi,

 

I needs to redirect only when last string matches as I dont wana redirect whole site.

 

example below

 

--->From

 

existing irule attached with external https vServer. currently its not working

 

when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with "/documents/.pdf" } { HTTP::respond 301 Location "[HTTP::uri]" } }

 

3 Replies

  • Hi korai,

    try this:

     when HTTP_REQUEST {
    
    
     if { [string tolower [HTTP::host]] == "abcsite" && [string tolower [HTTP::host]] ends_with ".pdf" } { 
     HTTP::respond 301 Location "https://xyz/details/overview[HTTP::uri]" 
     } 
     }
    

    It was not working because you use [HTTP::host] in order to check an URI

    use [HTTP::host] for check host

    and [HTTP::uri] in order to check an uri

    so in the irule that i provid you i checked that the host is abcsite and the uri end with ".pdf".

    you can add an additional condition in order to validate that the uri begin with "/documents/":

     when HTTP_REQUEST {
    
    
     if { ([string tolower [HTTP::host]] == "abcsite") && ([string tolower [HTTP::host]] ends_with ".pdf") && ([string tolower [HTTP::uri]] starts_with "/documents/") } { 
    
     HTTP::respond 301 Location "https://xyz/details/overview[HTTP::uri]" 
    
     } 
    
    
     }
    

    Regards

  • Above iRule has syntax error. I have bit modified iRule and added

    HTTP::path
    function to make condition more easy. you can modify based on requirements.

        when HTTP_REQUEST {
        if {[string tolower [HTTP::path]] equals "/save/samples/documents/chop-employe.pdf"}
           { 
                HTTP::respond 301 Location "https://newlocation/employee/overview[HTTP::uri]"  
            }
        }
    
    • Korai_331784's avatar
      Korai_331784
      Icon for Altostratus rankAltostratus

      Hi,

       

      Many thanks , I am try to get approval to test this and will update you.