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

Redirect single URL (hostname) only.

Hien_Truong
Cirrus
Cirrus

i need to redirect single (none wildcard) from www.abc.com to def.ghk.lmn.com

This is a single URL. Please do not redirect any traffic for sub folders or other URLs in the domain.

My below irule is not working. please advise what is wrong with it. i appreciate your input.

when HTTP_REQUEST {

  if {[HTTP::host] equals "www.abc.com"}{

    if {not ([HTTP::uri] starts_with "/")}{

      HTTP::redirect "https://def.ghk.lmn.com"

    }

  }

}

Thanks

1 ACCEPTED SOLUTION

Hien_Truong
Cirrus
Cirrus

​your irule works perfectly. I appreciate your input and thanks for your support.

View solution in original post

3 REPLIES 3

Hello Hien.

Try this:

when HTTP_REQUEST {
  if {[getfield [HTTP::host] : 1] equals "www.abc.com"}{
    if {not ([HTTP::uri] starts_with "/")}{
      HTTP::redirect "https://def.ghk.lmn.com[HTTP::uri]"
    }
  }
}

Remember that, base on your initial idea, redirection won't occur if you use this URL

https://www.abc.com/

And i should work if you use any other

https://www.abc.com/*

Regards,

Dario.

Regards,
Dario.

SanjayP
MVP
MVP

Alternatively,

when HTTP_REQUEST {
 if {([string tolower [HTTP::host]] eq "www.abc.com") and ( [HTTP::uri] eq "/" ) }{
 HTTP::respond 301 Location "https://def.ghk.lmn.com"
 return
    }
 }

Hien_Truong
Cirrus
Cirrus

​your irule works perfectly. I appreciate your input and thanks for your support.