Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Irule working, But incorrect statement taking effect

IRONMAN
Cirrostratus
Cirrostratus

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?

 

 

1 ACCEPTED SOLUTION

 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

View solution in original post

2 REPLIES 2

 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

IRONMAN
Cirrostratus
Cirrostratus

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

I am new to irule, so missed it.