cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

We basically want to redirect www.ecpurchasing.com to https://ecpurchasing.com. Right now the rule in the load balancer simply redirects http to https. External clients that use the Referrer URL for authentication validation only accepts request coming from https://ecpurchasing.com without “www”.

this virtual supports a number of sites using a SAN cert. The SAN cert includes ecpurchasing.com as well as www.ecpurchasing.com but the application needs to receive requests just from https://ecpurchasing.com.

How to use this snippet:

when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www.ecpurchasing";} { #HTTP::redirect "https://[findstr [string tolower [HTTP::host]] "www.ecpurchasing"; 4][HTTP::uri]" HTTP::redirect "http://[string range [HTTP::host] 4 end][HTTP::uri]" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }

Code :

when HTTP_REQUEST {
    if {[string tolower [HTTP::host]] starts_with "www.ecpurchasing"} {
       #HTTP::redirect "https://[findstr [string tolower [HTTP::host]] "www.ecpurchasing" 4][HTTP::uri]"
        HTTP::redirect "http://[string range [HTTP::host] 4 end][HTTP::uri]"
    } else {
        HTTP::redirect "https://[HTTP::host][HTTP::uri]"
    }
}

Tested this on version:

11.5
Comments

this seems simple enough but broke my site when i applied it, all https stopped working and i get page cant be displayed. my irule is as follows:

 

when HTTP_REQUEST {

  if {[string tolower [HTTP::host]] starts_with "www.jarvis"} {

    #HTTP::redirect "https://[findstr [string tolower [HTTP::host]] "www.jarvis" 4][HTTP::uri]"

    HTTP::redirect "http://[string range [HTTP::host] 4 end][HTTP::uri]"

  } else {

    HTTP::redirect "https://[HTTP::host][HTTP::uri]"

  }

}

Version history
Last update:
‎29-Mar-2017 05:23
Updated by:
Contributors