Forum Discussion

Pete_Paiva_7147's avatar
Pete_Paiva_7147
Icon for Nimbostratus rankNimbostratus
Apr 27, 2017

iRule redirect based on 403 or 404 response

Hello,

 

I'm looking for some assistance creating an iRule that will do the following:

 

If you go to:

 

http://projects.mysite.com/sites/alp-socialmedia

 

and you get either a 403 or 404 redirect to

 

https://collaboration.mysite.com/sites/alp-socialmedia

 

Would need the iRule to work for the following sites:

 

projects.mysite.com

 

projectext.mysite.com

 

teamspace.mysite.com

 

teamspaceext.mysite.com

 

 

Thanks, Pete

 

2 Replies

  • Hi,

    you can try this irule... and modify it to support all your hostnames.

    when HTTP_REQUEST {
        if {[HTTP::host] equals "projects.mysite.com" && [HTTP::uri] equals "/sites/alp-socialmedia"} {
            set redirect_available 1
        } else {
            set redirect_available 0
        }
    }
    
    when HTTP_RESPONSE {  
        if { $redirect_available && (([HTTP::status] eq "403") || ([HTTP::status] eq "404")) } {
             HTTP::respond 302 Location "https://collaboration.mysite.com/sites/alp-socialmedia"
        }
    }    
    
  • Hi,

    try this one:

    when HTTP_REQUEST {
        set uri [HTTP::uri]
        if {[HTTP::host] equals "projects.mysite.com" } {
            set redirect_available 1
        } else {
            set redirect_available 0
        }
    }
    
    when HTTP_RESPONSE {  
        if { $redirect_available && (([HTTP::status] eq "403") || ([HTTP::status] eq "404")) } {
             HTTP::respond 302 Location "https://collaboration.mysite.com$uri"
        }
    }