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

IRULE to redirect traffic from URL to another URL except for specific URI

dolly_pandit
Nimbostratus
Nimbostratus

HI Everyone,

 

I am looking for an irule where any traffic from host abc.com should redirect to bbc.com expect when it has URI of /XYZ on host abc.com.

 

I tried below irule but it is creating a loop .

 

when HTTP_REQUEST {

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

 HTTP::redirect "https://abc.com/xyz"

 }

 elseif { [HTTP::host] eq "abc.com" } {

 HTTP::redirect "https://bbc.com"

 }

}

4 REPLIES 4

dolly_pandit
Nimbostratus
Nimbostratus

  can you help me with this?

Hi, sorry my delay.

Let me try another option besides our friends.

Do you need to redirect only when host is abc.com and path starts with /xyz?

 

e.g.

1. http(s)://abc.com/xyz - Goto https://bbc.com/xyz

2. http(s)://abc.com/xyz/abc - Goto https://bbc.com/xyz/abc

3. http(s)://abc.com/xyzabc - Goto https://bbc.com/xyzabc

4. http(s)://abc.com/xyz?param=value - Goto https://bbc.com/xyz?param=value

5. http(s)://abc.com/Xyz - Do nothing

6. http(s)://abc.com/abc/xyz - Do nothing

7. http(s)://bbc.com/xyz - Do nothing

 

Code:

when HTTP_REQUEST {
  if { [HTTP::host] eq "abc.com" && [HTTP::uri] starts_with "/xyz" } {
    HTTP::redirect "https://bbc.com[HTTP::uri]"
  }
}

Regards.

Samir
MVP
MVP

You can try below irule. which will help to achieve your requirements.

when HTTP_REQUEST {
	if { ([string tolower[HTTP::host]] equals "abc.com") and ([HTTP::uri] starts_with "/xyz") } {
		HTTP::redirect "https://[HTTP::host][HTTP::uri]"
	}
	elseif {[string tolower[HTTP::host]] equals "abc.com")} {
	HTTP::redirect "https://bbc.com" 
		}
} 

Let us know if any issue.

Abed_AL-R
Cirrostratus
Cirrostratus

Try this:

when HTTP_REQUEST {
    if { ([HTTP::host] equals "abc.com") } {
	if { (not [HTTP::uri] starts_with "/xyz") } {
	HTTP::redirect "https://bbc.com" 
	}
    }
}