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

Redirect the domain name on URL, but keep path as the original URI path

NN
Altostratus
Altostratus

Hi All,

I'm trying to create an iRule which help me to redirect only the domain name. For example 

I want to redirect www.example.com/europe/login  to www.dr-example.com/europe/login

or www.example.com/usa/login  to www.dr-example.com/usa/login

There are several paths available, and any path that the user attempts should be redirected to the new domain name + path

1 ACCEPTED SOLUTION

Hi @NN , 

you can do it with this : 

when HTTP_REQUEST {
  if { [HTTP::host] equals "www.example.com"} {
    HTTP::redirect "https://www.dr-example.com[HTTP::path]"
 }
}


using [HTTP::path] >>> Returns your path in each URI. 
so if path changed in each request , redirection will happen only on host name and keep the path as it is. 

GoodLuck 🙂 

_______________________
Regards
Mohamed Kansoh

View solution in original post

1 REPLY 1

Hi @NN , 

you can do it with this : 

when HTTP_REQUEST {
  if { [HTTP::host] equals "www.example.com"} {
    HTTP::redirect "https://www.dr-example.com[HTTP::path]"
 }
}


using [HTTP::path] >>> Returns your path in each URI. 
so if path changed in each request , redirection will happen only on host name and keep the path as it is. 

GoodLuck 🙂 

_______________________
Regards
Mohamed Kansoh