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.

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
 
}
 
}

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
 
}]

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"
  }
}

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.

please try the below irule

when HTTP_REQUEST {
 
 HTTP::redirect https://[HTTP::host]/something
 
  }

Nope Mazhar, unfortunately it’s not working.

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

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.