Forum Discussion

Eric_123944's avatar
Eric_123944
Icon for Nimbostratus rankNimbostratus
Mar 06, 2013

default document and parameter based on host header

Hi I'm quite new to this, so please forgive me if this is something that you've seen before and have already answered.

 

I have an iRule that I wrote as more of a proof of concept. Basically I want to take connections to the default document and re-direct them with a parameter based on part of the host name. The following does what I want, but I'm looking for a better way to do it that can scale, to say 300 host names... From what I understand, this should be something that can be done using the scan command, but to be honest, it's a bit confusing for me.

 

 

 

when HTTP_REQUEST {

 

if { ([HTTP::host] equals "site1.domain.com") and ([HTTP::uri] equals "/") } {

 

HTTP::respond 301 Location "https://site1.domain.com/aaaa/bbbb/page.aspx?site=site1"

 

event disable

 

}

 

if { ([HTTP::host] equals "site2.domain.com") and ([HTTP::uri] equals "/") } {

 

HTTP::respond 301 Location "https://site2.domain.com/aaaa/bbbb/page.aspx?site=site2"

 

event disable

 

}

 

 

}

 

 

Any help you could offer would be appreciated

 

Thanks

 

6 Replies

  • Is it safe to say that you're always redirecting away from "/"? If so, you could use a data group based on the host and the new URI:

    ltm data-group internal /Common/host_test_group {

    records {

    site1.domain.com {

    data /aaaa/bbbb/page.aspx\?site=site1

    }

    site2.domain.com {

    data /aaaa/bbbb/page.aspx\?site=site2

    }

    }

    type string

    }

    
    when HTTP_REQUEST {
    if { ( [HTTP::uri] equals "/" ) and ( [class match [string tolower [HTTP::host]] equals host_test_group] ) } {
     found a matching host - redirect
    HTTP::respond 301 Location [class match -value [string tolower [HTTP::host]] equals host_test_group]
    }
    }
    

  • That works beautifully! Thank you very much Kevin. The potential with these units keeps blowing my mind.
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Just keep in mind that requests to the default document can also include the filename of the default document.

     

    In other words, if your web servers are configured to treat "index.html" as the default document a request to "/index.html" should be treated as a request to "/".

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    I just spotted another problem in your rule: you're using HTTP::uri. However, this includes the querystring. In other words, a request to "http://domain.com/?refid=campaign5" would not be redirected. You'll want to use HTTP::path instead.

     

    Note: the documentation mentions that only a question mark (?) is parsed as a seperator. Depending on the situation this may still allow someone to bypass the redirect.

     

  • That's definitively a good thing to be aware of. In my case, the root of my sites are empty except for a asp page as default document that does this redirect, so I'm not too worried about people trying to push parameters there and not being redirected. Still, it's a good thing to have, so I will use HTTP::path instead. Thanks Arie
  • That's definitively a good thing to be aware of. In my case, the root of my sites are empty except for a asp page as default document that does this redirect, so I'm not too worried about people trying to push parameters there and not being redirected. Still, it's a good thing to have, so I will use HTTP::path instead. Thanks Arie