Lucilius_223799
Sep 24, 2015Nimbostratus
iRule issues
I have some issues trying to create a iRule. I tried to create a redirect using
when HTTP_REQUEST {
if { ([HTTP::uri] contains "www.abc.def")}
{
HTTP::redirect "http://www.abc.com"
}
}
I'm not the handiest with iRules so I must have done something wrong but searching for the answers seems difficult.
I'm trying to make several of these with different versions similar to "" but also without the "abc.def" to make it redirect to the homepage directly.
Hello,
Welcome to DevCentral.
It seems like you're not using the correct function in your conditional IF-statement. That means, the block of code inside your conditional statement will never be processed. I've added a few comments to the code so you can get started with the most typical functions for HTTP services.
when HTTP_REQUEST { What's the difference of URL, Host, URI, Path, Query? URL = www.abc.com/asd/asd?asd111=11 [HTTP::host] function of this URL would return "www.abc.com" [HTTP::path] function of this URL would return "/asd/asd" [HTTP::uri] function of this URL would return "/asd/asd?asd111=11" [HTTP::query] function of this URL would return "asd111=11" The correct version of this code can be found below. Tip: by using HTTP::redirect you always issue a 302 redirect. I don't recommend this function at all. Instead, I recommend you get used to a slightly harder alternative, HTTP::respond which allows you to have a direct control of the redirect method and optinal HTTP headers if you wish to include them with the redirect. if { [HTTP::host] contains "www.abc.def" }{ HTTP::respond 301 location "http://www.abc.com" } }