Forum Discussion
ringoseagull_77
Mar 25, 2011Nimbostratus
irule to remove www. prefix from URIs
Hi,
I'm sure this has been covered but a search brings up a lot of threads using the same words
I need an irule which just strips out the www. from an http request, eg redirect www.mysite.com to mysite.com
Can someone point me towards one please?
- hooleylistCirrostratusHere you go:
when HTTP_REQUEST { Check if the host starts with www. if {[string tolower [HTTP::host]] starts_with "www."}{ Redirect with the www. prefix removed to the same URI HTTP::redirect "http://[string range [HTTP::host] 4 end][HTTP::uri]" } }
- ringoseagull_77NimbostratusGreat, thanks for the quick response hoolio
- ringoseagull_77NimbostratusMy boss has just requested one that does the opposite, to redirect mysite.com to www.mysite.com.
- hooleylistCirrostratusSure:
when HTTP_REQUEST { Check if the host does not start with www. if {not ([string tolower [HTTP::host]] starts_with "www.")}{ Redirect with the www. prefix to the same URI HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } }
- ringoseagull_77NimbostratusThanks, I found this by searching, it will do the same job by the looks, unless the string to lower segment makes a difference?
- ringoseagull_77NimbostratusI've used your version anyway, and amended the redirect line to o https for the 443. Thanks hoolio.
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