Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

Redirect specifc URI to another URL

Hello, I tried to find on google but nothing matched my search. I need a simple redirect from www.domain.com/tickets/841 only to > https://www.anotherdomain.com/test/event/841/seatplan/

Any suggestions ? Thanks!

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi

It could be as simple as this

when HTTP_REQUEST {
    if {[string tolower [HTTP::host]] eq "www.domain.com")}{
        if {[string tolower [HTTP::uri]] eq "/tickets/841" } {
        HTTP::redirect "https://www.anotherdomain.com/test/event/841/seatplan/"
        }
    }
}

However, if your VIP is only hosting content from www.domain.com then you could omit the domain validation part. Also, again depending on your setup, you might want to include some redirect loop config if it is needed

0
Comments on this Answer
Comment made 11-Apr-2018 by Chenco 62

Hi,

Thank you for the replay, guys!

The first answer is doing the job. But there is an issue with it:

When accessing via url directly : https://www.domain.com/tickets/841 - it is working, and redirecting to the: https://www.anotherdomain.com/test/event/841/seatplan/

in a proper way.

But when accessing via url directly to : https://www.domain.com/tickets/841/ ( with / at the end) – it is not redirecting.. goes to the same url.

Appreciate if anyone could help.

Thank you!

0
Comment made 11-Apr-2018 by iaine 851

Try changing eq to starts_with

if {[string tolower [HTTP::uri]] eq "/tickets/841"

to

if {[string tolower [HTTP::uri]] starts_with "/tickets/841"

0
Comment made 11-Apr-2018 by Chenco 62

Hi,

Thank you so much! It is working

Have a nice day!

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hello,

You can use this irule no matter the number of the ticket. the ticket number can be dynamic and I think it's your need.

when HTTP_REQUEST {

set hostname [string tolower [HTTP::host]]
set uri [string tolower [HTTP::uri]]

    if {$host eq "www.domain.com" && $uri starts_with "/tickets/" }{
        set numberticket [string range $uri 9 end]
        set redirecturi "/test/event/$numberticket/seatplan/"
        HTTP::redirect "https://www.anotherdomain.com$redirecturi"
        }
}
0