Forum Discussion

Glenn_32883's avatar
Glenn_32883
Icon for Nimbostratus rankNimbostratus
Jun 14, 2010

Trying if/elseif irule...

Hi all,

 

 

Faced with what I think is some interaction between separate irules, I am trying to see if useing if/elseif would help.

 

 

I have an old domain that I want to redirect to my new domain, preserving the uri, and then for requests to the root folder, I have sub-folder I want to redirect to. It does not seem to work for me though.

 

 

Based on what I could learn (copy) from the forums, it looks like this.

 

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::host]] equals "myoriginal.ca" && [HTTP::uri] equals {/}} {

 

HTTP::redirect "https://mystore.net/ca/catalog/index.aspx"

 

} elseif { [string tolower [HTTP::host]] equals "www.myoriginals.ca" && [HTTP::uri] equals {/}} {

 

HTTP::redirect "https://mystore.net/ca/catalog/index.aspx"

 

} elseif { [string tolower [HTTP::host]] equals "myoriginals.ca" } {

 

HTTP::redirect "https://mystore.net[HTTP::uri]"

 

} elseif { [string tolower [HTTP::host]] equals "www.myoriginals.ca" } {

 

HTTP::redirect "https://mystore.net[HTTP::uri]"

 

} }

 

 

I tried just using the "endswith" wording for specifying the host name, but that has not worked for me in the past either.

 

 

I'd appreciate any input, thanks!

 

 

Glenn

1 Reply

  • Try this and see if it works out for you:

    
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::host]] {
    "myoriginal.ca" -
    "www.myoriginals.ca" { 
    if { [HTTP::uri] equals "/" } { HTTP::respond 301 Location "https://mystore.net/ca/catalog/index.aspx" }
    }
    "myoriginals.ca" -
    "www.myoriginals.ca" {
    if { [HTTP::uri] equals "/" } { HTTP::respond 301 Location "https://mystore.net[HTTP::uri]" }
    }
    }
    }
    

    Made the HTTP::redirect into a HTTP::respond because an HTTP::redirect is a 302 (Temporary). With HTTP::respond you can specify the HTTP::status to a 301 (Permanent)

    The "myoriginal.ca" - tells it to follow the same action as the one below it (you can keep on doing this if you have more that you want to follow the same action.