20-Oct-2020 11:28
Hi all - hoping this is a simple one here... i'm looking to create a generic irule to redirect www traffic to non-www traffic. In the example below, it redirects back to the original www. and loops. Is there a way to exclude "www." in the HTTP::redirect ?
I really do not want to have to create a host specific irule every time. Thank you for any assistance here.
when HTTP_REQUEST {
if {[string tolower [HTTP::host] ] starts_with "www." }{
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
Solved! Go to Solution.
20-Oct-2020
12:45
- last edited on
04-Jun-2023
21:14
by
JimmyPackets
Hi dgytech,
1. string map
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[string map {www. ""} [HTTP::host]][HTTP::uri]
return
}
}
2. string range
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[string range [HTTP::host] 4 end][HTTP::uri]
return
}
}
3. getfield
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[getfield [HTTP::host] "www." 2][HTTP::uri]
return
}
}
4. substr
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[substr [HTTP::host] 4][HTTP::uri]
return
}
}
20-Oct-2020
12:45
- last edited on
04-Jun-2023
21:14
by
JimmyPackets
Hi dgytech,
1. string map
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[string map {www. ""} [HTTP::host]][HTTP::uri]
return
}
}
2. string range
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[string range [HTTP::host] 4 end][HTTP::uri]
return
}
}
3. getfield
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[getfield [HTTP::host] "www." 2][HTTP::uri]
return
}
}
4. substr
when HTTP_REQUEST {
if { [HTTP::host] starts_with "www." } {
HTTP::redirect https://[substr [HTTP::host] 4][HTTP::uri]
return
}
}
20-Oct-2020 22:02
This is fantastically fantastic! I went with option #1, works perfectly. Thank you!!