iRule Recipe 1: Single URL Explicit Redirect
 Series Introduction 
 Let's face it: there aren't many people out there who have extensive experience with Tcl. Since iRules is a Tcl dialect, that means that finding a solid iRules solution can be ...
Updated Jun 06, 2023
Version 2.0VernonWells Employee
Employee
I am an F5 Solutions Architect for Service Providers in the Americas, focusing on Virtualization, SP protocols (Diameter, GTP, DNS) and programmability.
Prior to joining F5, I worked as a Wi-Fi Network Engineer for a large U.S. public University, as an Operations Engineer, a network management Software Engineer, and as a Technical Trainer.VernonWells Employee
Employee
Oct 12, 2018HTTP::hosthttp://site.com/newpath
This would produce an HTTP Request message similar to the following (I omit a number of likely headers that aren't relevant to this example):
GET /newpath HTTP/1.1
Host: site.com
Notice that the path element (i.e.,
/newpathHTTP::pathwhen HTTP_REQUEST {
    switch [string tolower [HTTP::host]] {
        "site.com" -
        "www.site.com" {
            if { [HTTP::path] eq "/newpath" } {
                HTTP::respond 301 Location "https://www.site2.com/newpath"
            }
        }
    }
}
I use
switchHTTP::hoststring tolowerif { [string tolower [HTTP::host]] eq "site.com" or [string tolower [HTTP::host]] eq "www.site.com" } { ... }
Having said all of this, I strongly recommend that you consider using a Local Traffic Policy.