Forum Discussion
Redirect domain apex to www, retain URL/protocol
- May 12, 2017
Hi and welcome,
Recommend to take a look at ready-made iRules in Codeshare to get started. Start by making minor adjustments to someone else's code and learn that way. Basic iRule writing skills are a must when working with BigIP LTM.
This code will accomplish your current task
when CLIENT_ACCEPTED { Default to HTTPS set proto "https" if { [TCP::local_port] eq "80" }{ set proto "http" } } when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "website.com" }{ HTTP::respond 301 Location "$proto://www.website.com[HTTP::uri]" Connection Close event disable } }
Requires HTTP profile attached to your Virtual Server
Rgds,
Hi and welcome,
Recommend to take a look at ready-made iRules in Codeshare to get started. Start by making minor adjustments to someone else's code and learn that way. Basic iRule writing skills are a must when working with BigIP LTM.
This code will accomplish your current task
when CLIENT_ACCEPTED {
Default to HTTPS
set proto "https"
if { [TCP::local_port] eq "80" }{
set proto "http"
}
}
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] eq "website.com" }{
HTTP::respond 301 Location "$proto://www.website.com[HTTP::uri]" Connection Close
event disable
}
}
Requires HTTP profile attached to your Virtual Server
Rgds,
- Jesse_Reinhart_May 12, 2017Nimbostratus
Thanks so much! I was reading this when you replied:
 
https://devcentral.f5.com/s/articles/the101-irules-ndash-introduction-to-irules
 
However, I was unaware of codeshare. I'll definitely check that out!
 
- Jesse
Recent Discussions
Related Content
* 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