Forum Discussion
8 Replies
- SurgeonRet. Employee
You can create an iRule to do it for you using http_request event. if you have multiple URLs to redirect you can use switch command. As alternative you can use stream profile to replace all .test.com to .result.com.
- Samir_Jha_52506Noctilucent
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_343098Nimbostratus
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_343098Nimbostratus
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_52506Noctilucent
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]" } }