Forum Discussion

kraigk_52257's avatar
kraigk_52257
Icon for Nimbostratus rankNimbostratus
May 02, 2014

Moving IIS hosting.asp redirects to iRules

Need help moving IIS redirects to iRule. We have a long list of CNAME DNS records pointing to one IIS web server where we have a "hosting.asp" that does redirection. Some redirects are for sites and pages on the server itself and others are to completely different servers. Host header values are matched up to the CNAME's

<%
Response.buffer=true
select case (Request.ServerVariables("SERVER_NAME"))
case "url1.company.com"
Response.redirect "/redirect.htm"
case "url2.company.com"
Response.redirect "http://anyname1.company.com/services/directory"
case "url2.company.com"
Response.redirect "https://anyplace2.company.compro/profile/Unsolicited/webpage.htm"
end select
%>

We've recently moved this IIS server behind the LTM and are terminating SSL there. I'd like to move all this asp to iRule. Any help would be appreciated.

6 Replies

  • Depending on how many redirects there are you could use either a case select or a datagroup.

    With the datagroup, create one with a name of the site and the value as the URi you want to redirect to then use an iRule similar to below.

    when HTTP_REQUEST { HTTP::redirect [class lookup [HTTP::host] datagroup1] }

    If you only have a couple to do you may want to use a case select switch statement.
    
    switch [URI::query [HTTP::host]] {
       option1 { set selected_node uri1 }
       option2  { set selected_node uri2 }
       }
        HTTP::redirect selected_node
    
        or of course you could have the redirect in the switch statement, it depends if you want to use the URI later on for logging etc.. or to make it easier to read.
    
  • Thanks for the quick response. I have a bunch of these redirect, 20 or more so I'll give the datagroup a try.

     

  • e.g.

     config
    
    [root@ve11a:Active:In Sync] config  tmsh list ltm data-group internal redirect_class
    ltm data-group internal redirect_class {
        records {
            url1.company.com/ {
                data /redirect.htm
            }
            url2.company.com/ {
                data http://anyname1.company.com/services/directory
            }
            url3.company.com/ {
                data https://anyplace2.company.compro/profile/Unsolicited/webpage.htm
            }
        }
        type string
    }
    [root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      set hostpath [string tolower [HTTP::host][HTTP::path]]
      if { [class match -- $hostpath starts_with redirect_class] } {
        HTTP::redirect [class match -value -- $hostpath starts_with redirect_class]
      }
    }
    }
    
     test
    
    [root@ve11a:Active:In Sync] config  curl -Ik https://url1.company.com
    HTTP/1.0 302 Found
    Location: /redirect.htm
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve11a:Active:In Sync] config  curl -Ik https://url2.company.com
    HTTP/1.0 302 Found
    Location: http://anyname1.company.com/services/directory
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve11a:Active:In Sync] config  curl -Ik https://url3.company.com
    HTTP/1.0 302 Found
    Location: https://anyplace2.company.compro/profile/Unsolicited/webpage.htm
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Thanks to both of you. This works like a charm. I hadn't used string datagroups only IP lists and I'm sold. Much appreciated.

     

  • Just make sure that the URI's are HTTPS failing that apply an iRule containing the following to the HTTP version of your VIP

     

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