Forum Discussion
You could use getfield function to grep host name.
iRule will be some thing like below. Paste the comments if any help require.
when HTTP_REQUEST {
if { [HTTP::host] contains "test.com"} {
HTTP::respond 301 Location "https://[getfield [HTTP::host] ".test.com" 1].result.com[HTTP::uri]
}
}
Cheers...
- Thiyagu_343098May 28, 2018Nimbostratus
Hi, I have prepared the below script for an URL redirection based on host name with top level domain value. Can you please advise whether I have made any error or any where I have to change the logic?
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with ".testold1.com"}{ set newurl [string map -nocase {".testold1.com" ""}[HTTP::host] ".testnew.com" 1] HTTP::respond 301 Location "http://.[HTTP::host $ newurl][HTTP::uri] } else if {[string tolower [HTTP::host]] starts_with ".testold.com"}{ set newurl [string map -nocase {".testold.com" ""}[HTTP::host] ".testnew.com" 1] HTTP::respond 301 Location "http://.[HTTP::host $ newurl][HTTP::uri] } }
OR
when HTTP_REQUEST { if { ([HTTP::host] contains ".testold1.com") { HTTP::respond Location 301 "https://[getfield [HTTP::host] ".testold1.com" 1].testnew[HTTP::uri] } else if { ([HTTP::host] contains ".testold2.com") { HTTP::respond Location 301 "https://[getfield [HTTP::host] ".testold2.com" 1].testnew[HTTP::uri] } }
- Thiyagu_343098May 29, 2018Nimbostratus
Hello All, I have tried the below script and it is throwing the error while saving the irule. Could you please help me to know anything syntax I have to change with the below script?
when HTTP_REQUEST { if { [HTTP::host] contains "test.com"} { HTTP::respond 301 Location "https://[getfield [HTTP::host] ".test.com" 1].result.com[HTTP::uri] } }
Your quick help would be appreciable.
Regards, Thiyagu
- Samir_Jha_52506May 29, 2018Noctilucent
See below(comma is missing at end)
when HTTP_REQUEST { if { [HTTP::host] contains "test.com"} { HTTP::respond 301 Location "https://[getfield [HTTP::host] ".test.com" 1].result.com[HTTP::uri]" } }
- Thiyagu_343098May 29, 2018Nimbostratus
Thanks a lot F5_rock.
Could you please help me to know what the below function does?
HTTP::respond 301 Location "https://[getfield [HTTP::host] ".test.com" 1].result.com[HTTP::uri]"
It is responding to the client that the url has been changed temporarily. of this which piece is doing the function of replacing the host name?
Thanks a lot in advance for your help.
Regards, Thiyagu
- Samir_Jha_52506May 29, 2018Noctilucent
Is it working as per ur requirement? Click Yes to help others.. :)
 
Will help you to understand getfield function.. go through below link
 
- Thiyagu_343098Jul 03, 2018Nimbostratus
Hello All, I have applied the below tcl for the for the redirection from abc.test1.com to abc.test2.com. For some reason the redirection is not working.
Could you please help me to troubleshoot where the logic going wrong in the below script?
when HTTP_REQUEST { if {[string tolower [HTTP::host]] contains "test1.com"}{ set newurl [string map -nocase {"test1.com" ""} [[HTTP::host] "test2" 1]] HTTP::respond 301 Location "https://[HTTP::host $newurl][HTTP::uri]" } } ------------------------------------------------------------------
Regards, Thiyagu