Forum Discussion

BaluV_160328's avatar
BaluV_160328
Icon for Nimbostratus rankNimbostratus
Jul 02, 2014

URL Rewrite iRule Help Requested

Hi All,

 

Would appreciate if someone help me in verifying the following iRule..

 

My Requirement is that I have 2 URLs which resolves to the same IP address, the rewrite should take effect based on the URL.

 

dms-pd.abc.com and dms-dev.abc.com resolves to IP address 1.2.3.4

 

  1. If domain/host is dms-pd.abc.com, then redirect to http://10.10.10.1:50005/sap/
  2. If domain/host is dms-dev.abc.com, then redirect to http://10.10.10.2:8000/sap/

iRule Created and needs verification:

 

rule vip-1.2.3.4-irule { when HTTP_REQUEST { if { [HTTP::uri] == "/" } { HTTP::redirect "http://[HTTP::host]/irj/portal" } elseif { [string tolower [HTTP::uri]] starts_with "/irj" or [string tolower [HTTP::uri]] starts_with "/webdynpro" or [string tolower [HTTP::uri]] starts_with "/rtmfCommunicator" } { pool pool-10.10.10.10-50000 } elseif { ([HTTP::host] equals "dms-pd.abc.com") and ([HTTP::uri] starts_with "/sap") } { pool pool-10.10.10.1-50005} elseif { [string tolower [HTTP::uri]] starts_with "/sap" } { pool pool-10.10.10.2-8000}

 

5 Replies

  • what about this?

    when HTTP_REQUEST {
      switch -glob [HTTP::path] {
        "/" {
          HTTP::redirect "http://[HTTP::host]/irj/portal" 
        }
        "/sap*" {
          switch [HTTP::host] {
            "dms-pd.abc.com" { pool pool-10.10.10.1-50005 }
            "dms-dev.abc.com" { pool pool pool-10.10.10.2-8000 }
            default {
               do something
            }
          }
        }
        "/irj*" -
        "/webdynpro*" -
        "/rtmfCommunicator*" {
          pool pool-10.10.10.10-50000 
        }
        default {
           do something
        }
      }
    }
    
    • BaluV_160328's avatar
      BaluV_160328
      Icon for Nimbostratus rankNimbostratus
      Thanks for your quick response.. However, what could be the action for the following function ? default { do something }
  • what about this?

    when HTTP_REQUEST {
      switch -glob [HTTP::path] {
        "/" {
          HTTP::redirect "http://[HTTP::host]/irj/portal" 
        }
        "/sap*" {
          switch [HTTP::host] {
            "dms-pd.abc.com" { pool pool-10.10.10.1-50005 }
            "dms-dev.abc.com" { pool pool pool-10.10.10.2-8000 }
            default {
               do something
            }
          }
        }
        "/irj*" -
        "/webdynpro*" -
        "/rtmfCommunicator*" {
          pool pool-10.10.10.10-50000 
        }
        default {
           do something
        }
      }
    }
    
    • BaluV_160328's avatar
      BaluV_160328
      Icon for Nimbostratus rankNimbostratus
      Thanks for your quick response.. However, what could be the action for the following function ? default { do something }
  • what could be the action for the following function ?

     

    i just put it in case you want to do something when request does not match defined patterns. you can also delete it.