Forum Discussion

wyuen_99269's avatar
wyuen_99269
Icon for Altostratus rankAltostratus
Mar 06, 2015

Irule to URL rewriting

How would you write an irule? A domain name "A" ip address points to F5. I would like keep the name of domain on the browser but under redirect internally with changing the URL on the Browser

 

12 Replies

  • Hi,

    Just another question, how would you write a a domain A has to redirect to B but would like the domain header to be domain A. 
    

    Thank you

  • If you're wanting to change ABC.com to Def.com server side but not redirect the clients browser you would use

    when HTTP_REQUEST {
        HTTP::host "def.com"
    }
    
    • Arie's avatar
      Arie
      Icon for Altostratus rankAltostratus
      HTTP::host only works in 11.5+, though.
  • If you're wanting to change ABC.com to Def.com server side but not redirect the clients browser you would use

    when HTTP_REQUEST {
        HTTP::host "def.com"
    }
    
    • Arie's avatar
      Arie
      Icon for Altostratus rankAltostratus
      HTTP::host only works in 11.5+, though.
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    For older versions you can use HTTP::header to replace the host:

    when HTTP_REQUEST {
        HTTP::header replace Host "www.domain2.com"
    }
    
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    when HTTP_REQUEST {
    
        if { [string tolower [HTTP::host] equals "www.domainA.com" ] } {
    
            HTTP::respond 301 Location "http:://www.domainB.com[HTTP::uri]"
    
        }
    
        if { [string tolower [HTTP::host] equals "www.domainB.com" ] } {
    
            HTTP::header replace Host "www.domainA.com"     
    
        }
    
    }
    
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Version 11.5+:

    when HTTP_REQUEST {
    
        if { [string tolower [HTTP::host] equals "www.domainA.com" ] } {
    
            HTTP::respond 301 Location "http:://www.domainB.com[HTTP::uri]"
    
        }
    
        if { [string tolower [HTTP::host] equals "www.domainB.com" ] } {
    
            HTTP::host "www.domainA.com"        
    
        }
    
    }
    
  • This another request for something I looking for do :

    How would write using IRULE for condition :

    If Domain = "canextest.cfmws.com" and Path = "/payment" then

      redirect to another URL internally
    

    elso go the whatever URL was entered.

  • when HTTP_REQUEST {
        if { [HTTP::host] equals "canextest.cfmws.com" && [HTTP::uri] starts_with "/payment" } {
            HTTP::redirect http://some.url.com
        }
    }
    
  • Hi,

    I tested the script running under 11.2.1, it does not work. It does redirect to the site. Would it possible 
    rewrite the procedure under 11.2.1.
    
    when HTTP_REQUEST {
    
    if { [string tolower [HTTP::host] equals "www.domainA.com" ] } {
    
        HTTP::respond 301 Location "http:://www.domainB.com[HTTP::uri]"
    
    }
    
    if { [string tolower [HTTP::host] equals "www.domainB.com" ] } {
    
        HTTP::host "www.domainA.com"        
    
    }
    

    }

    Thank you