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

iRule for redirection

Koalan
Cirrus
Cirrus

Hi,

 

I am not really familiar with iRule, can somebody help me?

 

So the scenario is that a user wants to access a f5 vip which will be redirected to a certain site:

 

user access onboarding.abc.com/uk (f5 vip) and it should redirect to https://ask.service.com/management.do

 

how can i attain this? it's needs to be exactly as onboarding.abc.com/uk

 

Thanks!

5 REPLIES 5

Hello  ,

 

You can even achieve your requirement using LTM Policy option. Also you can try below iRule.

 

 when HTTP_REQUEST {

if { [HTTP::host] contains "onboarding.abc.com"}{

if { [HTTP::uri] starts_with "/uk"}{ 

HTTP::redirect https://ask.service.com/management.do

}

}

 

Hope it works!

Mayur

 

Samir
MVP
MVP

Policy is always a better choice. I agree with  's iRule. Small correction needed; There is no points to add multiple if condition. Find the below iRule, Hope it will work for you.

when HTTP_REQUEST {
	if { ([HTTP::host] equals "onboarding.abc.com") && ([HTTP::uri] starts_with "/uk") } {
		HTTP::respond 301 Location "https://ask.service.com/management.do"
	}
}

Koalan
Cirrus
Cirrus

thank you guys! i will try this!

Koalan
Cirrus
Cirrus

btw whats the difference between that HTTP::respond 301 to the normal redirect ?

Samir
MVP
MVP

HTTP::redirect:- This command always sends an HTTP 302 (Temporary Redirect) status code. HTTP request to the specified URL, or replaces the current response with a redirect to the specified URL.

 

HTTP::respond:- This command sends a response to the client telling the client to send a fresh request to the URL you specify. A 301 redirect means that the page has permanently moved to a new location.