01-Dec-2020 08:50
Hi Im looking for help with an irule to achieve the following:
if someone visits https://www.site.com/abc/def or https://www.site.com/abc/def/ it redirects them to https://www.domain.com - we have the following irule in place but it doesnt capture the second uri with trailing '/' https://www.site.com/abc/def/
when HTTP_REQUEST {
if { ([HTTP::host] equals "www.site.com") and ([HTTP::path] ends_with "/abc/def") } {
HTTP::redirect https://www.domain.com
}
}
Any help appreciated!
01-Dec-2020 10:32
Hi cymru81,
You should use starts_with instead of ends_with.
When using starts_with, /abc/def/x path matches with condition.
If you don't want redirect for /abc/def/x, you can use this iRule:
when HTTP_REQUEST {
if { [HTTP::host] equals "www.site.com" } {
switch [HTTP::path] {
"/abc/def" -
"/abc/def/" { HTTP::redirect https://www.domain.com }
}
}
}
02-Dec-2020 00:54
Hi eaa
Thanks for responding, unfortunately that still doesnt work when changing to starts_with
We still want visitors to be able to navigate to /abc/ but with this irule applied its redirecting them to www.domain.com ?
02-Dec-2020 01:58
Hi,
Only /abc/def and /abc/def/ match this iRule. /abc/ does not match.
02-Dec-2020 05:27
could there be something else in my original rule causing this as if i go to www.site.com/abc it blanket redirects to www.domain.com ?
02-Dec-2020 05:47
We always should look at possibilities, to confirm this, I'd suggest to put loggings in the Irule block and see where this redirection is getting triggered.
02-Dec-2020 06:12
thanks - how do i add this to my existing rule?
04-Dec-2020 02:19
Lets go with your own rule,
when HTTP_REQUEST {
if { ([HTTP::host] equals "www.site.com") and ([HTTP::path] ends_with "/abc/def") } {
log local0. "CLIENT=[IP::client_addr] has matched If block, Host=[HTTP::host] and matches Path=[HTTP::path] ends_with"
HTTP::redirect https://www.domain.com
log local0. "CLIENT=[IP::client_addr] has been redirected to www.domain.com"
}
}
You should see the logging in your /var/log/ltm file.