Forum Discussion

Randy_Johnson_L's avatar
Randy_Johnson_L
Icon for Nimbostratus rankNimbostratus
Mar 06, 2017

Evaluate full URL for empty URI / Path ?

I need to deploy an iRule that will perform a redirect, based on the HTTP::uri or HTTP::path being empty. This needs to take into account a user trying 'http://server.company.com' and 'http://server.company.com/' and redirect based on the existence of ANY uri. That is... if the URI string is present, it will redirect to http://server.company2.com[HTTP::uri] and if the URI is NOT present (or is 'empty', even with no trailing 'slash' it should redirect to http://server.company3.com.

 

I seem to be getting caught in evaluating for an 'empty' URI, in the form of 'http://server.company.com/'

 

Any help or references ??

 

3 Replies

  • Randy, can you show what your iRule looks like? Only advice I have for now is to use HTTP::path for the condition because HTTP::uri also contains the query string so depending on how you built your condition, you might get unexpected results.

    So I would do something like this (note that I added [HTTP::uri] in both redirects in case you need to keep the query string) :

    if { ([HTTP::path] eq "" ) or ([HTTP::path] eq "/")} {
      HTTP::respond 301 Location http://server.company3.com[HTTP::uri]
      }
    else {
      HTTP::respond 301 Location http://server.company2.com[HTTP::uri]
      }
    
  • Is it something you want to try?

     

    when HTTP_REQUEST { if { [HTTP::header host] eq "company.com" } or { [HTTP::header host] eq "company.com/" } { HTTP::redirect "http://server.company2.com[HTTP::uri]" }

     

    else

     

    { HTTP::redirect "; } }

     

  • Hi,

     

    Browser never send empty uri in request.

     

    The request format is :

     

    GET /path HTTP/1.X   

    Or (for some http 1.0 browser)

     

    GET /path

    The uri is always at least /

     

    When you do not enter any path in the browser, it append /

     

    The code is

     

    if {[HTTP::path] eq "/"} {
      HTTP::respond 301 Location http://server.company3.com/
      }
    else {
      HTTP::respond 301 Location http://server.company2.com[HTTP::uri]
      }