Forum Discussion

JGTRAN_142005's avatar
JGTRAN_142005
Icon for Nimbostratus rankNimbostratus
Jan 23, 2014

need help creating an iRule

hi all, Hope you all doing well. Could someone help me with creating an iRule? I would like to create an iRule which will forward all http/https request to go to a URL.

For example: abc.com www.abc.com http://abc.com etcc. will all go to https://www.abc.com

Here's the current iRule i have but it's re-directing all traffic to https://abc.com . I need it all to go to https://www.abc.com instead.

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 "https://[string range [HTTP::host] 4 end][HTTP::uri]"

} }

Thank you very much for your assistance, JT

  • 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 "https://[string range [HTTP::host] 4 end][HTTP::uri]"
    

    } }

  • hi all, i found the answer after searching the forum.

     

    when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "example.com" }{ HTTP::respond 301 Location "http://www.[HTTP::host][HTTP::uri]" } }