Forum Discussion

IRONMAN's avatar
IRONMAN
Icon for Cirrostratus rankCirrostratus
Aug 05, 2020
Solved

Irule working, But incorrect statement taking effect

HI , Any one please guide me here

 

I have below irule,

 

  • when HTTP_REQUEST {
  •  
  • if { [string tolower [HTTP::host]] equals "test.new.com" } {
  • pool new }
  •  
  • elseif { ! ([HTTP::host] starts_with "www.") } {
  •   HTTP::redirect https://www.[HTTP::host][HTTP::uri]}
  •  
  • else { log local0. "No match found for [HTTP::uri]" } }
  •  
  • }
  • }

 

When HTTP request coming with not matching host name "test.new.com" , it is taking elseif statement by adding www, host uri, not going to else statement, last one

But the statement elseif is only for starts_with, www request. like www.123.com.

 

example:

 

When http request coming with host name " flow.com"

I am seeing URL changing in browser www.flow.com

it is taking elseif condition !

 

any correction?

 

 

  •  As your elseif statement is elseif { ! ([HTTP::host] starts_with "www.") },

     

    So when request is coming for host flow.com, it is not equal (!) to condition starts_with "www" so it is matching elseif statement and redirecting it as per action statement - HTTP::redirect https://www.[HTTP::host][HTTP::uri]}

     

    Can you please elaborate your overall requirement to help further?

     

    Mayur

2 Replies

  •  As your elseif statement is elseif { ! ([HTTP::host] starts_with "www.") },

     

    So when request is coming for host flow.com, it is not equal (!) to condition starts_with "www" so it is matching elseif statement and redirecting it as per action statement - HTTP::redirect https://www.[HTTP::host][HTTP::uri]}

     

    Can you please elaborate your overall requirement to help further?

     

    Mayur

  • Thanks Mayur, I understood, it is very clear. I missed it elseif { ! .

    I am new to irule, so missed it.