For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

samo's avatar
samo
Icon for Nimbostratus rankNimbostratus
Jul 11, 2019

HTTP redirect when Path is / and host is not FQDN

I wrote a simple irule to do HTTP redirect:

when HTTP_REQUEST {
  if { !([string tolower [HTTP::host]] ends_with "mycompany.com") } { append [HTTP::host] "mycompany.com" }
   
  if { [HTTP::path] eq "/" or [HTTP::path] eq "" } {
  HTTP::redirect "http://application.mycompany.com/ABC"
  }
}

I expect my iRule to redirect:

http://application/ or http://application.mycompany.com/

to

http://application.mycompany.com/ABC

But it is not the case, the iRule is not doing anything when host is not FQDN and it seems the condition evaluation doesn't work for empty path (/)

1 Reply

  • Hi,

    There are some possibilities to get this working.

    e.g.

    when HTTP_REQUEST {
        set host [getfield [HTTP::host] : 1]
        if { not ( [string tolower $host] ends_with "mycompany.com" ) } {
            append host ".mycompany.com"
            if { [HTTP::path] ne "/" } {
                HTTP::redirect "http://$host[HTTP::uri]"
            }
        }
        if { [HTTP::path] eq "/" } {
            HTTP::redirect "http://$host/ABC"
        }
    }

    Test #1:

     # curl-apd -v --resolve application:80:172.30.30.100 http://application

    * Added application:80:172.30.30.100 to DNS cache

    * Rebuilt URL to: http://application/

    * Hostname application was found in DNS cache

    *  Trying 172.30.30.100...

    * Connected to application (172.30.30.100) port 80 (#0)

    > GET / HTTP/1.1

    > Host: application

    > User-Agent: curl/7.47.1

    > Accept: */*

    >

    * HTTP 1.0, assume close after body

    < HTTP/1.0 302 Moved Temporarily

    < Location: http://application.mycompany.com/ABC

    < Server: FRONTEND

    * HTTP/1.0 connection set to keep alive!

    < Connection: Keep-Alive

    < Content-Length: 0

    <

    * Connection #0 to host application left intact

    Test #2:

    # curl-apd -v --resolve application:80:172.30.30.100 http://application/mypath

    * Added application:80:172.30.30.100 to DNS cache

    * Hostname application was found in DNS cache

    *  Trying 172.30.30.100...

    * Connected to application (172.30.30.100) port 80 (#0)

    > GET /mypath HTTP/1.1

    > Host: application

    > User-Agent: curl/7.47.1

    > Accept: */*

    >

    * HTTP 1.0, assume close after body

    < HTTP/1.0 302 Moved Temporarily

    < Location: http://application.mycompany.com/mypath

    < Server: FRONTEND

    * HTTP/1.0 connection set to keep alive!

    < Connection: Keep-Alive

    < Content-Length: 0

    <

    * Connection #0 to host application left intact

    Test #3:

    # curl-apd -v --resolve application.mycompany.com:80:172.30.30.100 http://application.mycompany.com

    * Added application.mycompany.com:80:172.30.30.100 to DNS cache

    * Rebuilt URL to: http://application.mycompany.com/

    * Hostname application.mycompany.com was found in DNS cache

    *  Trying 172.30.30.100...

    * Connected to application.mycompany.com (172.30.30.100) port 80 (#0)

    > GET / HTTP/1.1

    > Host: application.mycompany.com

    > User-Agent: curl/7.47.1

    > Accept: */*

    >

    * HTTP 1.0, assume close after body

    < HTTP/1.0 302 Moved Temporarily

    < Location: http://application.mycompany.com/ABC

    < Server: FRONTEND

    * HTTP/1.0 connection set to keep alive!

    < Connection: Keep-Alive

    < Content-Length: 0

    <

    * Connection #0 to host application.mycompany.com left intact

    I hope it helps.

    Regards