Forum Discussion

nlong_67651's avatar
nlong_67651
Icon for Nimbostratus rankNimbostratus
Sep 15, 2010

https and www redirect

I am trying to figure out how to redirect the initial requests for http://sitename.com/* and https://sitename.com/* to https://www.sitename.com/* Is this easily accomplished using one irule? All SSL connections are terminating directly on the webservers, but since the initial connection to https://sitename.com is HTTP, I don't believe this matters.

 

 

I understand how to do a basic subdomain redirect, and how to redirect to https, but I'm unsure how to tie the two together. Here is the redirect I'm currently using:

 

 

when HTTP_REQUEST {

 

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

 

}

 

2 Replies

  • Hi nlong,

    I suppose if you have 2 virtuals you can run this irule

    
    when HTTP_REQUEST {
       if {[HTTP::host] eq "sitename.com" } {
          HTTP::redirect "https://www.[HTTP::host]/[HTTP::uri]"
          }
    }
    

    or

    
    when HTTP_REQUEST {
       switch -glob [HTTP::host] {
            "sitename.com" { HTTP::redirect "https://www.[HTTP::host]/[HTTP::uri]" }
         }
    }
    

    I hope this helps

    Bhattman

  • Bhattman, unless I'm mistaken, doing [HTTP::host]/[HTTP::uri] would give you two "/"s since the "/" is part of the URI

    I'd go with this:

    when HTTP_REQUEST {
       if { [string tolower [HTTP::host]] eq "sitename.com" } {
          HTTP::redirect "https://www.sitename.com[HTTP::uri]"
          }
    }