Forum Discussion

NewTOF501_15047's avatar
NewTOF501_15047
Icon for Nimbostratus rankNimbostratus
Jul 07, 2014

irule to check domain and redirect is not working

when HTTP_REQUEST { if { [HTTP::host] equals "www.data.gov.bh" } { HTTP::uri [string map -nocase {"/" "/wps/portal/data/"} [HTTP::uri]] } elseif { [HTTP::host] equals"www.biciactions.bh" } {HTTP::redirect "http://www.biciactions.bh/wps/portal/BICI" } elseif { [HTTP::host] equals "www.fsupport.gov.bh" } { HTTP::uri "/wps/portal/fsupport/"}

 

}

 

please advice why above is not working

 

18 Replies

  • i tried this when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "www.data.gov.bh" { HTTP::redirect "http://www.data.gov.bh/wps/portal/data"} "www.fsupport.gov.bh" { HTTP::redirect "http://www.fsupport.gov.bh/wps/portal/fsupport"} "www.biciactions.bh" { HTTP::redirect "http://www.biciactions.bh/wps/portal/BICI"} } but it is also not working
  • In the 1st attempt you are rewriting the uri that goes to the server, but the client thinks they are getting what ever page they actually requested. You are going to end up with a lot of extra path information being injected if for example the client already requested http://www.data.gov.bh/wps/portal/data/ it all looks very wrong.

     

    The second attempt is going to cause redirection loops.

     

    I think what you want is something like... if { [HTTP::host] equals "www.data.gov.bh" and [HTTP::uri] equals "/" } { HTTP::redirect "http://www.data.gov.bh/wps/portal/data" }

     

    • NewTOF501_15047's avatar
      NewTOF501_15047
      Icon for Nimbostratus rankNimbostratus
      it tried when HTTP_REQUEST { if { [HTTP::host] equals "www.data.gov.bh" and [HTTP::uri] equals "/" } { HTTP::redirect "http://www.data.gov.bh/wps/portal/data" } elseif { [HTTP::host] equals "www.biciactions.bh" and [HTTP::uri] equals "/" } { HTTP::redirect "http://www.biciactions.bh/wps/portal/BICI" } } but still not working
    • Sam_Hall's avatar
      Sam_Hall
      Icon for Nimbostratus rankNimbostratus
      Are you sure? When I access those domains the redirects seem to be working as expected. When I type www.data.gov.bh into my browser it lands me on http://www.data.gov.bh/wps/portal/data for example. What exactly would you like to happen?
  • In the 1st attempt you are rewriting the uri that goes to the server, but the client thinks they are getting what ever page they actually requested. You are going to end up with a lot of extra path information being injected if for example the client already requested http://www.data.gov.bh/wps/portal/data/ it all looks very wrong.

     

    The second attempt is going to cause redirection loops.

     

    I think what you want is something like... if { [HTTP::host] equals "www.data.gov.bh" and [HTTP::uri] equals "/" } { HTTP::redirect "http://www.data.gov.bh/wps/portal/data" }

     

    • NewTOF501_15047's avatar
      NewTOF501_15047
      Icon for Nimbostratus rankNimbostratus
      it tried when HTTP_REQUEST { if { [HTTP::host] equals "www.data.gov.bh" and [HTTP::uri] equals "/" } { HTTP::redirect "http://www.data.gov.bh/wps/portal/data" } elseif { [HTTP::host] equals "www.biciactions.bh" and [HTTP::uri] equals "/" } { HTTP::redirect "http://www.biciactions.bh/wps/portal/BICI" } } but still not working
    • Sam_Hall_83788's avatar
      Sam_Hall_83788
      Icon for Nimbostratus rankNimbostratus
      Are you sure? When I access those domains the redirects seem to be working as expected. When I type www.data.gov.bh into my browser it lands me on http://www.data.gov.bh/wps/portal/data for example. What exactly would you like to happen?
  • thanks i tried below but it does not works

    [root@centos1 ~] curl -I http://www.data.gov.bh
    HTTP/1.0 302 Found
    Location: http://www.data.gov.bh/wps/portal/data
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@centos1 ~] curl -I http://www.fsupport.gov.bh
    HTTP/1.0 302 Found
    Location: http://www.fsupport.gov.bh/wps/portal/fsupport
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@centos1 ~] curl -I http://www.biciactions.bh
    HTTP/1.0 302 Found
    Location: http://www.biciactions.bh/wps/portal/BICI
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    

    have you ever used http analyzer tool? it may be helpful.

    HttpFox

    https://addons.mozilla.org/en-US/firefox/addon/httpfox/