Forum Discussion
dgytech
Oct 20, 2020Altostratus
Generic irule to redirect www to non-www
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....
- Oct 20, 2020
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 } }
Oct 20, 2020
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
}
}
- dgytechOct 21, 2020Altostratus
This is fantastically fantastic! I went with option #1, works perfectly. Thank you!!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects