Forum Discussion

piowis_321863's avatar
piowis_321863
Icon for Nimbostratus rankNimbostratus
May 24, 2017

Redirect when port 80 is visible in url

Hello, I am just wondering is it possible to get redirect only if port 80 in url is visible? I mean if application send url like sampleurl:80/sample/context redirect it to sampleurl:8889/sample/context

 

I have tried something like this if { ( [HTTP::host] contains ":80" ) and ( [HTTP::uri] starts_with "/sample/context" ) } { pool Sample_Pool_8889 }

 

Thanks in advance.

 

4 Replies

  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus
    • do you want to redirect the url the user sees on the browser or send traffic to pool?
  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus

    Try

    when HTTP_REQUEST {
    if {  ( [HTTP::host] contains ":80" ) and ( [HTTP::uri] starts_with "/sample/context" )}
    {
    HTTP::redirect https://[HTTP::host]:8889[HTTP::uri] 
    }
    }   
    
  • Hi,

    your irule seems right. Maybe you have to rewrite request host header:

    when HTTP_REQUEST {
        if {  ( [HTTP::host] contains ":80" ) and ( [HTTP::uri] starts_with "/sample/context" )}
        {
             HTTP::host "sampler:8889"
             pool Sample_Pool_8889 
        }
    }  
    
  • Try with that one:

    when HTTP_REQUEST {
    if { ( [HTTP::host] ends_with ":80" ) and ( [HTTP::uri] starts_with "/sample/context" ) } {
        HTTP::header replace Host "sampler:8889"
        pool Sample_Pool_8889 
    }
    else {
        pool Some_Other_Pool
    }
    }