Forum Discussion

ryank5589's avatar
ryank5589
Icon for Nimbostratus rankNimbostratus
Feb 18, 2020

iRule assistance based on URI and source address

Hey all!

 

I have an application that currently allows for all users to connect to a java and non java version based on the URI that you browse to. I would like to allow only a specific range of IP addresses to be able to reach the java version, and if you are not coming from that specific range, then I want the users to be forwarded to the non java version.

 

I tried writing an iRule, but I think I am getting caught up with the redirect to the nonjava version. Any assistance would help.

 

when HTTP_REQUEST { 

if { ([HTTP::uri] contains "/java/version") && ([class match [IP::client_addr] equals JAVA-VERSION-NETS]) } {

pool My-Web-Pool

} else { HTTP::redirect https://application.com/nonjava/version }

}

 

Assistance would be appreciated.

 

thanks you ,

 

RK

 

  • Following iRule code should remove the redirect loop to the nonjava version.

     

    when HTTP_REQUEST { 
     
        if { ([HTTP::uri] contains "/java/version") && ([class match [IP::client_addr] equals JAVA-VERSION-NETS]) } {
     
            pool My-Web-Pool
     
        } else { 
        
                if { [HTTP::uri] contains "/java/version" } { 
                
                HTTP::redirect https://application.com/nonjava/version
                
                }
    			
    			pool My-Web-Pool
        }
    }

     

  • Hope below irule will solve your issue

    when HTTP_REQUEST { 
    if { [class match [IP::client_addr] equals JAVA-VERSION-NETS] } {
    	HTTP::redirect "https://application.com/java/version" 	
    	} 
    else {
    	HTTP::redirect "https://application.com/nonjava/version"
    	}
    }
  • Samir,

     

    Thanks for the response! I don't understand how the irule you provided distinguishes between the java and nonjava version for the initial traffic. For example, both the java and non java versions are hosted on the same pool members within the same pool, but the only difference is the uri. Any idea how to write an irule for that?

  • NAG's avatar
    NAG
    Icon for Cirrostratus rankCirrostratus

    Following iRule code should remove the redirect loop to the nonjava version.

     

    when HTTP_REQUEST { 
     
        if { ([HTTP::uri] contains "/java/version") && ([class match [IP::client_addr] equals JAVA-VERSION-NETS]) } {
     
            pool My-Web-Pool
     
        } else { 
        
                if { [HTTP::uri] contains "/java/version" } { 
                
                HTTP::redirect https://application.com/nonjava/version
                
                }
    			
    			pool My-Web-Pool
        }
    }

     

      • NAG's avatar
        NAG
        Icon for Cirrostratus rankCirrostratus

        That's great.

        Could you mark this question as solved please.