Forum Discussion

Yesh1923's avatar
Yesh1923
Icon for Nimbostratus rankNimbostratus
Jan 17, 2023

Multiple http_request iRules not working Same Virtual server

 

how to merge this 2 irule

when HTTP_REQUEST {

if { ([string tolower [HTTP::host]] equals "energy.com")

HTTP::respond 301 location "https://www.[HTTP::host][HTTP::uri]" Connection Close
}
}

 

 

when HTTP_REQUEST {

if { ([string tolower [HTTP::host]] equals "corporate.ndtv.com")} {
HTTP::respond 301 location "https://www.ndtv.com" Connection Close
}
}

 

 

13 Replies

  • Hi iyyappan321,

    when HTTP_REQUEST {
    	if { [string tolower [HTTP::host]] equals "energy.com" } {
    		HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
    		return
    	} elseif { [string tolower [HTTP::host]] equals "corporate.ndtv.com" } {
    		HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
    		return
    	}
    }

    switch version

    when HTTP_REQUEST {
    	switch [string tolower [HTTP::host]] {
    		"energy.com" {
    			HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
    			return
    		}
    		"corporate.ndtv.com" {
    			HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
    			return
    		}
    	}
    }

     

    • Yesh1923's avatar
      Yesh1923
      Icon for Nimbostratus rankNimbostratus

       

      when HTTP_REQUEST {

      if { ([string tolower [HTTP::host]] equals "energy.com")

      HTTP::respond 301 location "https://www.[HTTP::host][HTTP::uri]" Connection Close
      }
      }

      when HTTP_REQUEST {

      if { ([string tolower [HTTP::host]] equals "corporate.ndtv.com")} {
      HTTP::respond 301 location "https://www.ndtv.com" Connection Close
      }
      }

       

      when HTTP_REQUEST {
      switch [string tolower [HTTP::host]] {
      "exxonmobil.eu" {
      HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
      return
      }
      "corporate.exxonmobil.com.qa" {
      HTTP::respond 301 Location "https://www.exxonmobil.com.qa" "Connection" "Close"
      return
      }
      }
      }


      when HTTP_REQUEST {
      if { [string tolower [HTTP::host]] equals "energy.com" } {
      HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
      return
      } elseif { [string tolower [HTTP::host]] equals "corporate.ndtv.com" } {
      HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
      return
      }
      }

       

       

      much appreciate your response 

      one more info need - syntax for add more url 

      how to add these website as well -- goodenergy.com,  oddenergy.com  etc ... in below 

       

      when HTTP_REQUEST {

      if { [string tolower [HTTP::host]] equals "energy.com" } {
      HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
      return

      &

       


      when HTTP_REQUEST {
      switch [string tolower [HTTP::host]] {
      "energy.com" {
      HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
      return

       

      >>>>>>>>>>>>

      how add multi sites in below syntax


      marketing.ndtv.com" as well

       

      "corporate.ndtv.com" {
      HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
      return

       

      • when HTTP_REQUEST {
        	switch [string tolower [HTTP::host]] {
        		"energy.com" -
        		"goodenergy.com" -
        		"oddenergy.com" {
        			HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
        			return
        		}
        		"corporate.ndtv.com" -
        		"marketing.ndtv.com" {
        			HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
        			return
        		}
        	}
        }

        You can review the article at the link for switch command usage.

        https://clouddocs.f5.com/api/irules/switch.html

  • Hi 

    If you share one more method, you can also leverage datagroup.

     

    when HTTP_REQUEST {
    	if { class match [string tolower [HTTP::host]] equals DATAGROUP-NAME } {
    		HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
    		return
    	} elseif { class match [string tolower [HTTP::host]] equals DATAGROUP-NAME  } {
    		HTTP::respond 301 Location "https://www.ndtv.com" "Connection" "Close"
    		return
    	}
    }

     

    DATAGROUP-NAME Include

    Type String

    String : 

    energy.com
    goodenergy.com
    oddenergy.com

  • hi nimbos

    how to merge these http_request , could you please help 

    when HTTP_REQUEST {
    if {([HTTP::header values "True-Client-IP"] equals "203.82.36.24") or ([HTTP::header values "True-Client-IP"] equals "11.50.154.146")
    or ([HTTP::header values "True-Client-IP"] equals "180.91.158.114") or ([HTTP::header values "True-Client-IP"] equals "180.131.18.113")
    or ([HTTP::header values "True-Client-IP"] equals "103.11.158.98") or ([HTTP::header values "True-Client-IP"] equals "11.54.23.2") or ([HTTP::header values "True-Client-IP"] equals "91.218.114.26") or
    ([HTTP::header values "True-Client-IP"] equals "91.28.11.4") or ([HTTP::header values "True-Client-IP"] equals "92.63.8.47") or
    }{
    HTTP::respond 400 content "site currently unavailable, Please try again later"
    }
    }

     

    ********************************************


    when HTTP_REQUEST {
    if { [string tolower [HTTP::host]] equals "energy.com" } {
    HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
    return
    }
    elseif { [string tolower [HTTP::host]] equals "ndtv.com" } {
    HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
    return
    }
    elseif { [string tolower [HTTP::host]] equals "corporate.ndtv.com" } {
    HTTP::respond 301 Location "https://www.ndtv.co" "Connection" "Close"
    return

    }
    }

     

     

     

     

     

     

     

     

    • Yesh1923's avatar
      Yesh1923
      Icon for Nimbostratus rankNimbostratus

      or can we have two working irule ,one for http_request another irule for block external ips 

      • Hooni_L's avatar
        Hooni_L
        Icon for Cirrus rankCirrus

        Yesh1923 

        I think use date-group list and 'IF' on irule.

        I couldn't test it, but I checked that it was set up in the equipment.

        refer below irule and datagroup list:

         

        when HTTP_REQUEST {
            if { [class match [HTTP::header values "True-Client-IP"] eq dg-client-ip]  } {
                HTTP::respond 400 content "site currently unavailable, Please try again later"
            } elseif { [class match [HTTP::host] eq dg-domain] } {
                HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]" "Connection" "Close"
                return
            }
        }

         

         

         

  • how to merge these 2 irule in single irule 

     

    when HTTP_REQUEST {

     if { ([string tolower [HTTP::host]] equals "essar.com") && (([string tolower [HTTP::path]] eq "/en")

    or ([string tolower [HTTP::path]] eq "/en/")) }

    {

        HTTP::respond 301 location "https://essar.com/en-gb/"

    elseif { ([string tolower [HTTP::host]] equals "essar.com") && ([string tolower [HTTP::path]] contains "/wholesale-fuels") }

    {

        HTTP::respond 301 location "https://www.essar.com/wholesale-fuels" "Connection" "Close"

      }

     

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 

    when HTTP_REQUEST {

           

    HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1][HTTP::uri]" TCP::close

     

      }

     

    • Hi iyyappan321,

      when HTTP_REQUEST {
      	if { ([string tolower [HTTP::host]] equals "essar.com") && (([string tolower [HTTP::path]] eq "/en") or ([string tolower [HTTP::path]] eq "/en/")) } {
      		HTTP::respond 301 Location "https://essar.com/en-gb/"
      		return
      	} elseif { ([string tolower [HTTP::host]] equals "essar.com") && ([string tolower [HTTP::path]] contains "/wholesale-fuels") } {
      		HTTP::respond 301 Location "https://www.essar.com/wholesale-fuels" "Connection" "Close"
      		return
      	}
      	else {
      		HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
      		TCP::close
      	}
      }

      You need to use this iRule in non 443 virtual server. Otherwise, redirect loop occurs. 

      • Yesh1923's avatar
        Yesh1923
        Icon for Nimbostratus rankNimbostratus

        hi enes thanks for your response 

        i used below rule , but i can able to access only - energy.com site , if i access essar.com its not getting redirect to "https://corporate.essar.com/fr-fr"

        my requirement is i want to access both - energy.com , if i access  essar.com -- have to redirect to "https://corporate.essar.com/fr-fr"

        please help 

        when HTTP_REQUEST {

        if { ([string tolower [HTTP::host]] equals "essar.co.uk") && (([string tolower [HTTP::path]] eq "/en") or ([string tolower [HTTP::path]] eq "/en/")) } {
        HTTP::respond 301 location "https://wholesalefuels.essar.co.uk/en-gb/"
        }

        elseif { ([string tolower [HTTP::host]] equals "energy.com") } {
        HTTP::respond 301 location "https://www.energy.com" Connection Close
        }
        elseif { ([string tolower [HTTP::host]] equals "essar.com") && ([string tolower [HTTP::path]] contains "fr-fr/wholesale-fuels") } {
        HTTP::respond 301 location "https://www.essar.com/fr-FR/wholesale-fuels"
        }
        elseif { ([string tolower [HTTP::host]] equals "www.essar.com") && ([HTTP::path] eq "/") } {
        HTTP::respond 301 location "https://corporate.essar.com/fr-fr"
        }
              else  {
        HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
        }