Forum Discussion

Tom_Thunem_9204's avatar
Tom_Thunem_9204
Icon for Nimbostratus rankNimbostratus
Oct 12, 2009

URL redirect when URL is lacking a domain name

Hello,

 

 

I have a situation where they want to save the user some typing. They want to redirect http://abc to http://abc.com. Haven't been able to find the syntax for this. All of my rules assume the domain was entered. Whatever the solution is, I assume the abc.com URL will carry to the downstream VIP's and other apps that require the appended domain name.

 

 

Thanks.

5 Replies

  • Is this on an intranet environment where "abc" will be resolved by a name lookup? Assuming that's the case, then as long as the host IP for "abc" is configured as a virtual server on the BIG-IP, you could create an iRule like this:

    when HTTP_REQUEST { 
       if { [HTTP::host] eq "abc" } { 
         HTTP::header replace "Host" "abc.com" 
       } 
     }

    -Joe
  • here is the iRule I have built. It doesn't seem to be working as the FQDN doesn't appear to be getting passed on to the authentication piece of our app. In the browser, the user enters "http://chargeit", they are then taken to a login screen. That screen requires the FQDN for authentication. That being "chargeit-test.avnet.com".

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] eq "chargeit-test" } {

     

    HTTP::header replace "Host" "chargeit-test.avnet.com"

     

    }

     

    }
  • You could add logging to the iRule and use a browser plugin like HttpFox for Firefox or Fiddler for IE to view the client to VIP communication.

     
     when HTTP_REQUEST { 
      
        log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" 
      
         Check if host is chargeit-test 
        if { [HTTP::host] eq "chargeit-test" } { 
      
           log local0. "[IP::client_addr]:[TCP::client_port]: Replacing host header." 
      
            Replace the Host header 
           HTTP::header replace "Host" "chargeit-test.avnet.com" 
        } 
     } 
     

    Aaron
  • here's what I have thus far. Same results if I use double-quotes around Host in replace statement.

     

     

    when HTTP_REQUEST {

     

    Check if host is chargeit-test

     

    if { [HTTP::host] eq "chargeit-test" } {

     

    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"

     

    log local0. "[IP::client_addr]:[TCP::client_port]: Replacing host header."

     

    Replace the Host header

     

    HTTP::header replace Host "chargeit-test.avnet.com"

     

    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] after rewrite [HTTP::host][HTTP::uri]"

     

    }

     

    }

     

     

     

    Oct 13 08:49:49 tmm tmm[1637]: Rule chargeit-logging : 10.64.33.42:2589: GET request to chargeit-test/

     

    Oct 13 08:49:49 tmm tmm[1637]: Rule chargeit-logging : 10.64.33.42:2589: Replacing host header.

     

    Oct 13 08:49:49 tmm tmm[1637]: Rule chargeit-logging : 10.64.33.42:2589: GET after rewrite chargeit-test/

     

  • The HTTP::host value is cached, but the update is still done. If you want to see the effect of the change you could either check the server logs or log the value in a later priority HTTP_REQUEST event:

     
     when HTTP_REQUEST {  
      
        log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"  
      
         Check if host is chargeit-test  
        if { [HTTP::host] eq "chargeit-test" } {  
      
           log local0. "[IP::client_addr]:[TCP::client_port]: Replacing host header."  
      
            Replace the Host header  
           HTTP::header replace "Host" "chargeit-test.avnet.com"  
        }  
     }  
     when HTTP_REQUEST priority 501 { 
      
         log local0. "[IP::client_addr]:[TCP::client_port]: (501) [HTTP::method] request to [HTTP::host][HTTP::uri]"  
     } 
     

    Aaron