Rewrite (Search-Replace) HTML on the fly

From Tech-Wiki
Jump to: navigation, search

Back to iRules

This can also be done via LTM Rewrite profile

when HTTP_REQUEST {    
      set replace_content 0  
      if {[HTTP::uri] contains "/atoz/"} {    
          set replace_content 1    
      }    
   }    
      
  when HTTP_RESPONSE {  
    if {$replace_content equals "1"} {  
        # Disable the stream filter by default  
        STREAM::disable  
     
       # Check if response type is text  
       if {[HTTP::header value Content-Type] contains "text" and [HTTP::header "User-Agent"] contains "***"}{  
            # Replace  
            STREAM::expression "@123@xyz@ @456@xyz@"  
            # Enable the stream filter for this response only  
            STREAM::enable  
        }  
    }  
  }