cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP host and uri, and if there's a match, rewrite uri and redirect to new host- works if refresh

Nari
Nimbostratus
Nimbostratus

Hi All,

Truley appricate your time ...

The below iRule works only if we referesh the brower multiple times, redirection happens but HTML delays to load the page

Requirment: Redirect old host to new host and replace the URI content and redirect

http://test.com/class/results.asp?subject=

This should be redirected

https://www.results.com/school/name?subject=

I have replace replaced the URI content and redirect new URI to new HOST, works only if we refresh the brower continueosly

when HTTP_REQUEST {
log local0. "[HTTP::host][HTTP::uri]"
if { [HTTP::host] equals "test.com" && [HTTP::uri] contains "class/results.asp?subject=" } {
log local0. "[HTTP::host][HTTP::uri]"
set current_uri [HTTP::uri]
set newuri [string map {class/results.asp? school/name?} [HTTP::uri]]
log local0. "https://www.results.com$newuri"
HTTP::redirect "https://www.results.com$newuri"
}
if { [HTTP::host] equals "test.com" && [HTTP::uri] eq "/class" || [HTTP::uri] eq "/class.subject.asp" } {
HTTP::redirect "https://www.results.com"
return
}
}

Not sure of what i am doing worng in this iRule. Please advice.

Thanks,

2 REPLIES 2

AlexBCT
MVP
MVP

Hi, I hope you already found the answer, but if not, maybe this may help; 

In the IF statement, have you tried changing [HTTP::host] equals "test.com" to [HTTP::host] ends_with "test.com" ? 

Certain browsers and versions automatically add "www" to the beginning of the domain name, meaning it won't match the IF statements when you are using "equals".

Hope this helps. 

Hi Alex, Thank you for your response, yes finally it worekd after adding the below lines into the iRule...i thougt of captueing the host after responded to request ans somehow it worked fo rme..

if { [HTTP::has_responded] } {
return
}

Thanks,

Nari