Forum Discussion

Eddy_161863's avatar
Eddy_161863
Icon for Nimbostratus rankNimbostratus
Oct 06, 2015

f5 URL redirection

I am trying to setup a redirect based on the host in the URL. Is there any way to match two host values in the url and if it matches one of the condition, then redirect. I only want to change the host value in the redirect and want to keep the URI as is. I have setup an iRule something like this:

 

if { (([string tolower [HTTP::host]] equals "abc") || ([string tolower [HTTP::host]] equals "abc/")) } {

 

HTTP::redirect "http://abc.xyz.com[HTTP::uri]" }

 

It seems to me that it only works well for first condition but not for second condition. Am I doing something wrong or the syntax is different for v11?

 

Any help would be really apprecited.

 

10 Replies

  • Hi,

     

    / is not valid character in HTTP Host header. how do you try condition ([string tolower [HTTP::host]] equals "abc/") ?

     

  • Because some of the URL's work ok when I check for "abc/" in the host while some work with only "abc". this is a strange behavior that I have never seen before. looks like client is passing different host for different URL's. So the condition is if client simply enters in the url , they should get redirected to http://abc.xyz.com or [HTTP::uri] they should get redirected to http://abc.xyz.com/[HTTP::uri].

     

    What is the best way to redirect the host and keeping the URI?

     

    • Stanislas_Piro2's avatar
      Stanislas_Piro2
      Icon for Cumulonimbus rankCumulonimbus
      In URL http://abc/login.aspx?login=user&password=pass : - HTTP::host is abc - HTTP::uri is /login.aspx?login=user&password=pass - HTTP::path is /login.aspx - HTTP::query is login=user&password=pass So, there is no / character in HTTP::host
  • What you have should work for all valid (according to RFC) URL. I'd drop any request with a / in the Host headers

    if { [string tolower [HTTP::host]] equals "abc" } {
        HTTP::respond 301 Location "http://abc.xyz.com[HTTP::uri]" 
        return
    } elseif { [string tolower [HTTP::host]] ends_with "/" } {
        Host headers do not contain /
       HTTP::respond 400 content "Bad Request - host header"
       return
    }
    
  • Thanks for the feedback everyone.

     

    The issue I'm seeing is since xyz.com is internal domain and complete URL of the app is abc.xyz.com/HTTP::uri. so some users prefer to type only and the app team wants that whenever a user types it should get redirected to http://abc.xyz.com. because otherwise the application will break.

     

    Now, when i set redirect like this:

     

    if { [string tolower [HTTP::host]] equals "abc" { HTTP::redirect "http://abc.xyz.com[HTTP::uri]" }

     

    Some URL's work while some don't

     

    for example: gets redirected to http://abc.xyz.com/HTTP::uri but gets redirected to http//abc/ and not http://abc.xyz.com

     

    Any suggestion, could it be server issue?

     

    Thanks in advance.

     

    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus
      and also i see aborted for some requests in the browser....and they don't reach the server and gets aborted at f5.
  • F5 in between client and server, if a request is sent to F5 and match condition, it is handled by the irule before being sent to the server.

     

    each time, you post only a part of the irule, is there any other code in the irule with redirect action?

     

    How do you check redirect? with Firebug tool, with curl?

     

    Stan

     

  • Hi,yes, there is other code in the iRule but not related to redirect. this is the only code for redirect. Some URL's work without redirect but if I put this redirect condition the url's that were not working started to work and those were working before,failed with this redirect.

     

    I'm using IE inbuilt tool (F12 developer tool) to see what status I'm getting. I see aborted in the tool and page cannot be displayed.

     

  • you may have tcl error in Local Traffic Logs (or /var/log/ltm)

     

    please add return command after each HTTP::redirect command to prevent errors.