Forum Discussion
Grayson_149410
Nimbostratus
Sep 29, 2015irule remove "www."
Does anyone have an iRule that will remove the "www." part of a URL? I tried the following iRule, but it does not work.
when HTTP_REQUEST {
if { [HTTP::uri] equals "https://www.abc.xyz.com" } {
HTTP::redirect "https://abc.xyz.com"
}
}
Edit: Also, the site is certed using a *.abc.com wildcard certificate.
5 Replies
- Brad_Parker_139
Nacreous
Try this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www."}{ HTTP::redirect "https://[string map {www. ""} [string tolower [HTTP::host]]]" } }- Brad_Parker_139
Nacreous
if you want to keep the original URI use this when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www."}{ HTTP::redirect "https://[string map {www. ""} [string tolower [HTTP::host]]][HTTP::uri]" } }
- Brad_Parker
Cirrus
Try this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www."}{ HTTP::redirect "https://[string map {www. ""} [string tolower [HTTP::host]]]" } }- Brad_Parker
Cirrus
if you want to keep the original URI use this when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www."}{ HTTP::redirect "https://[string map {www. ""} [string tolower [HTTP::host]]][HTTP::uri]" } }
- IheartF5_45022
Nacreous
From an SEO perspective, a 301 redirect would be best;-
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www." } { HTTP::respond 301 Location "https://[substr [HTTP::host] 4][HTTP::uri]" content "" noserver return } }Alternatively, if you want the browser to continue to display the www. Host variant, you may want to proxy the request with a modified Host header rather than redirecting;
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www." } { HTTP::host [substr [HTTP::host] 4] } }
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
