Forum Discussion

Michael_Ozorows's avatar
Michael_Ozorows
Icon for Nimbostratus rankNimbostratus
Jan 24, 2018

Simple switch statement for URI redirection?

Hi all,

I've fumbled around and hitting brick walls. We want this application (by default) to go to website.com/irj/portal.

If website.com/abc is typed we want a http redirect

If website.com/123 is typed we want a http redirect.

I've read switch statement is more efficient than if elseif so I'm trying to get this working. Here's what I have:

when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
     "/sap/opu" { 
           HTTP::redirect "http://nwgtw.corp.nielsen.com/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html"
          }
     "/abc" { 
           HTTP::redirect "http://abc.com"
          }
     "/123" { 
           HTTP::redirect "http://123.com"
          }
     "/xyz" { 
           HTTP::redirect "http://xyz.com"
           }
 default {
          HTTP::redirect "https://website.com/irj/portal"
         }
   }
}

I tried removing default, tried "/" also tried "*" and all of them seem to be wanting to push this back to /xyz.com and I'm not quite sure why.

Any guidance here?
  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Caching? Try this one:

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::path]] {
            "/sap/opu" {
                HTTP::respond 301 Location "http://nwgtw.corp.nielsen.com/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html" Cache-Control no-cache Connection close
            }
            "/abc" {
                HTTP::respond 301 Location "http://abc.com" Cache-Control no-cache Connection close
            }
            "/123" {
                HTTP::respond 301 Location "http://123.com" Cache-Control no-cache Connection close
            }
            "/xyz" {
    
                HTTP::respond 301 Location "http://xyz.com" Cache-Control no-cache Connection close
    
            } default {
                HTTP::respond 301 Location "https://website.com/irj/portal" Cache-Control no-cache Connection close
            } 
        }
    }
    

    .