Forum Discussion

ukitsysadmin_95's avatar
ukitsysadmin_95
Icon for Nimbostratus rankNimbostratus
Nov 10, 2009

replace http::host headers

Is it possible to do the following

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] starts_with "preview.www."} {

 

 

I want to redirect to

 

 

HTTP::redirect "http://preview2.www."same domain name"

 

 

but I keep getting

 

 

preview2.www.preview.www.abc.com

 

 

We have hundreds/thousands of domain names and growing, example

 

 

abc.com

 

def.com

 

ghi.com

 

 

because the growing number of domains

 

 

I want the irule just to replace, preview.www."domain name" with preview2.www."same domain name"

 

 

so no matter what domain name I type preview.www.abc.co.uk or com or be etc, etc it will redirect to preview2.www.abc.co.uk or com or be etc, etc

 

 

type:

 

preview.www."any domain name" redirect to preview2.www."same domain name"

 

 

Hope this make sense ?

3 Replies

  • You can use the domain command to parse the domain from the HTTP::host value:

    http://devcentral.f5.com/Wiki/default.aspx/iRules/domain

     
     when HTTP_REQUEST { 
      
        log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]" 
      
        if { [string tolower [HTTP::host]] starts_with "preview.www."} { 
      
           log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://preview2.www.[domain [HTTP::host] 2]" 
           HTTP::redirect "http://preview2.www.[domain [HTTP::host] 2]" 
        } 
     } 
     

    Aaron
  • Actually, the domain command won't work for this scenario if you need to support example.com and example.co.uk...

    How about this instead:

     
      when HTTP_REQUEST {  
        
         log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]"  
        
         if { [string tolower [HTTP::host]] starts_with "preview.www."} {  
        
            log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to preview2.www.[getfield [string tolower [HTTP::host]] preview.www. 2]"  
            HTTP::redirect "http://preview2.www.[getfield [string tolower [HTTP::host]] preview.www. 2]" 
         }  
      }  
     

    Aaron
  • Thats excellent thank you,

     

     

    is it possible to keep the orginal url in the browser ?

     

     

    although preview.www. has redirected to preview2.www can the broswer still say preview.www."any domain name"