Forum Discussion

Sami_Sheikh_140's avatar
Sami_Sheikh_140
Icon for Nimbostratus rankNimbostratus
Feb 21, 2014

Hostname redirect to Subdirectory URL

Hi,

 

I am looking to create an iRule which would redirect users from: Http://example.com or https://example.com to https://example.com/example1/example.htm.

 

Currenty I have the F5 Virtual appliance 11.4 LTM so I am wondering if this is something that the F5 can handle.

 

Thanks

 

7 Replies

  • Well,

    the short answer: yes, the F5 can handle it.

    the longer answer: Do you want to just redirect any requests from http[s]://example.com/ to https://example.com/example1/example.htm? Or just specific ones?

    If you want all requests redirected: Usually you have a virtual-server for http and another one for https.

    For the virtual-server for http you could add a new irule containing:

    when HTTP_REQUEST {
        HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }
    

    for the virtual-server for https, you could add something like that:

    when HTTP_REQUEST {
        if { [HTTP::uri] eq "/" } {
            HTTP::redirect "/example1/example.htm"
        }
    }
    

    (Untested, but i guess you get the point)

    • Sami_Sheikh_140's avatar
      Sami_Sheikh_140
      Icon for Nimbostratus rankNimbostratus
      So I am unsure of what you mean by all requests or specific ones. If I understand what you are trying to say then I would say all requests, basically I could put the forward rule in IIS as well but I don't want to touch the server at all since it is an app server and is very delicate. So basically I have about 6 Virtual servers(3 for HTTP and 3 for HTTPS) for 3 different domains but pointing to the same servers and I would like for instance anybody from outside going to http(s)://example1.com to https://example.com/welcome/welcome.htm and http(s)://example2.com to https://example2.com/welcome/welcome.htm so and so forth. Will those Irule you posted above, can I achieve what I am trying to achieve here? Thanks again Rene
    • Rene_C_'s avatar
      Rene_C_
      Icon for Nimbostratus rankNimbostratus
      If you assign the first rule to the http - virtuals and the second one to the https-virtuals, this should do what you want.
  • Well,

    the short answer: yes, the F5 can handle it.

    the longer answer: Do you want to just redirect any requests from http[s]://example.com/ to https://example.com/example1/example.htm? Or just specific ones?

    If you want all requests redirected: Usually you have a virtual-server for http and another one for https.

    For the virtual-server for http you could add a new irule containing:

    when HTTP_REQUEST {
        HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }
    

    for the virtual-server for https, you could add something like that:

    when HTTP_REQUEST {
        if { [HTTP::uri] eq "/" } {
            HTTP::redirect "/example1/example.htm"
        }
    }
    

    (Untested, but i guess you get the point)

    • Sami_Sheikh_140's avatar
      Sami_Sheikh_140
      Icon for Nimbostratus rankNimbostratus
      So I am unsure of what you mean by all requests or specific ones. If I understand what you are trying to say then I would say all requests, basically I could put the forward rule in IIS as well but I don't want to touch the server at all since it is an app server and is very delicate. So basically I have about 6 Virtual servers(3 for HTTP and 3 for HTTPS) for 3 different domains but pointing to the same servers and I would like for instance anybody from outside going to http(s)://example1.com to https://example.com/welcome/welcome.htm and http(s)://example2.com to https://example2.com/welcome/welcome.htm so and so forth. Will those Irule you posted above, can I achieve what I am trying to achieve here? Thanks again Rene
    • Rene_C__129338's avatar
      Rene_C__129338
      Icon for Nimbostratus rankNimbostratus
      If you assign the first rule to the http - virtuals and the second one to the https-virtuals, this should do what you want.
  • Hi,

    Just to avoid too many redirects you could apply this iRule to your http virtual servers.

    when HTTP_REQUEST {
        HTTP::redirect "https://[getfield [HTTP::host] ":" 1]/welcome/welcome.htm"
    }
    

    I think you'll have a problem with the second iRule because the redirect statement is not complete, you have to define the full URL.

    when HTTP_REQUEST {
        if { [HTTP::uri] eq "/" } {
            HTTP::redirect "https://[getfield [HTTP::host] ":" 1]/example1/example.htm"
        }
    }