Forum Discussion

Ashraf1's avatar
Ashraf1
Icon for Nimbostratus rankNimbostratus
Feb 11, 2020

iRules appending after url

Hello F5 !!!

I am newbie in the world of load balancing, apologies if I am posting a silly question.

Recently I have published a https website, created a iRule to redirect from http to https using below

when HTTP_REQUEST {
if {[HTTP::host] equals "abc.com"}
{
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
else
{
HTTP::redirect "https://abc.com/[HTTP::uri]"
}
} 

Now I have a requirement to append a string after the url, example if some user is visiting abc.com, he should be redirected to https://abc.com/something.

Thanks in advance.

7 Replies

  • try this irule 
     
    when HTTP_REQUEST {
     
    if { ([HTTP::host] == "abc.com") and ([HTTP::uri] == "/*") } {
     
    HTTP::redirect https://[HTTP::host][HTTP::uri]
     
    }
     
    elseif { ([HTTP::host] == "abc.com")  } {
     
    HTTP::redirect https://[HTTP::host]/something
     
    }
     
    }
    • Ashraf1's avatar
      Ashraf1
      Icon for Nimbostratus rankNimbostratus

      Hello Ragu,

      When I tried, recieving below error,

      01070151:3: Rule [/Common/abc.com] error: /Common/abc.com:9: error: [undefined procedure: elseif][elseif { ([HTTP::host] == "abc.com") } {
       
      HTTP::redirect https://[HTTP::host]/something
       
      }]
  • wlopez's avatar
    wlopez
    Icon for Cirrocumulus rankCirrocumulus

    Generic http to https redirect, retaining the original URI of the request for http virtual server:

    when HTTP_REQUEST {
      HTTP::respond 301 Location "https://abc.com[HTTP::uri]"
    }

    https redirect to default page within https, for https virtual server:

    when HTTP_REQUEST {
      if { [HTTP::path] equals "/"} {
        HTTP::respond 301 Location "https://abc.com/something"
      }
    }
    • Ashraf1's avatar
      Ashraf1
      Icon for Nimbostratus rankNimbostratus

      Just to summarize, so I have to create two irules, one for the redirection of http traffic to https and other for adding "/something" at the end of the URL.

      • wlopez's avatar
        wlopez
        Icon for Cirrocumulus rankCirrocumulus

        The iRule for the http virtual server will cover the redirects to https for all requests. That will help mitigate situations like if someone forgets to type https on their browser. Without it they would get a timeout.

        The iRule for the https virtual server will simply make sure that if someone types the URL, they get redirected to the website's initial landing/login page. For example, if someone types 'https://abc.com', without the iRule they would be sent to the default setup on the servers. If you don't have any programing on the servers to redirect requests to path '/' to the initial login page '/web/login.php'. With the iRule the F5 will make sure that requests to the default path '/' get redirected to '/web/login.php', while leaving requests to any other paths intact.

  • mf5's avatar
    mf5
    Icon for Nimbostratus rankNimbostratus

    please try the below irule

    when HTTP_REQUEST {
     
     HTTP::redirect https://[HTTP::host]/something
     
      }
    • Ashraf1's avatar
      Ashraf1
      Icon for Nimbostratus rankNimbostratus

      Nope Mazhar, unfortunately it's not working.

       

      It's redirecting http request to https, however it's not appending /something.