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

Filter by:
  • Solution
  • Technology
Answers

Traffic redirection

" Tokenized string" [a-Z]{1,6}[0-9]{1,15} can anyone help me in writing an F5 irule for the following ?

I want to redirect the following URLs:-

1) https://sfobjtest.govnet.nsw.gov.au/id: tokenised_string 2) https://sfobjtest.govnet.nsw.gov.au/id: tokenised_string/.*

TO

https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/ tokenised_string

0
Rate this Question
Comments on this Question
Comment made 20-Feb-2018 by Rakesh 12

Hi Kai,

I applied the irule but it doesn't seem to work.

Just this simple redirection rule doesn't work:-

when HTTP_REQUEST {

  if { [string tolower [HTTP::host]] equals "sfobjtest.govnet.nsw.gov.au" } {

    HTTP::respond 301 Location "sfobjtest.govnet.nsw.gov.au:8443/#/documents"   } }

The URL "https://sfobjtest.govnet.nsw.gov.au";

doesn't redirects to

"https://sfobjtest.govnet.nsw.gov.au:8443/#/documents";

Please help if possible

0
Comment made 21-Feb-2018 by Kai Wilke 6973

Hi Rakesh,

if the iRule above does not work at all, then I would recommend to include some Debug-Log line to make sure the iRule gets executed...

when HTTP_REQUEST {
    log local0.debug "Debug: iRule executed"
    if { [string tolower [HTTP::host]] equals "sfobjtest.govnet.nsw.gov.au" } {
        log local0.debug "Debug: [string tolower [HTTP::host]] is matching the pattern"
        HTTP::respond 301 Location "sfobjtest.govnet.nsw.gov.au:8443/#/documents"
    } else {
        log local0.debug "Debug: [string tolower [HTTP::host]] is not matching the pattern"
    }
}

Note: Keep in mind, that almost every configuration change requires you to close any existing TCP-session. So better close/open your browser between the individual tests to get sure...

Cheers, Kai

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Rakesh,

you may take the snippet below as a starting point...

when HTTP_REQUEST {
    if { ( [string tolower [HTTP::host]] eq "sfobjtest.govnet.nsw.gov.au" )
     and ( [string tolower [HTTP::path]] starts_with "/id:" ) } then {
        HTTP::respond 307 Location "https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/[findstr [HTTP::path] "/id:" 4 "/"]"
    }
}

The iRule uses a [findstr [HTTP::path] "/id:" 4 "/"] syntax to parse the [HTTP::path] for the first ocourence of the string /id:, then skip 4 bytes (aka. /id: is skipped) and then take the remaining [HTTP::path] till the next ocourence of /.

Note: If the iRule does not work out for you, then please reply with Real-World examples of the two URLs formats that need to become redirected...

Cheers, Kai

0
Comments on this Answer
Comment made 01-Feb-2018 by Rakesh 12

Thanks Kai. It is valuable.

0
Comment made 01-Feb-2018 by Rakesh 12

I didn't properly write the Traffic redirection rules before. But here it is :- Would it be possible for you to help me in irules again? Thanks for your help.

The redirection rule mappings are as follows:

Note that the use of “” represents the Objective object ID value that is required in the URI, in order to load the required Objective content page in context. The ‘tokenised_string’ will always be of the format denoted by the regular expression:

• [a-Z]{1,6}[0-9]{1,15}

i.e. starts with at least one alphabetic character (case insensitive), repeatable up to 6 alphabetic characters; followed by at least one digit, repeatable up to 15 digits.

e.g. A82734, fA9632, eobjA294, B7623, qB944422


FROM

https://sfobjtest.govnet.nsw.gov.au/id: (tokenised_string)

https://sfobjtest.govnet.nsw.gov.au/id: (tokenised_string)/.*

TO

https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/ (tokenised_string)


FROM

https://sfobjtest.govnet.nsw.gov.au/docseach/id: (tokenised_string)

https://sfobjtest.govnet.nsw.gov.au/docseach/id: (tokenised_string)/.*

TO

https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/ (tokenised_string)


FROM

https://sfobjtest.govnet.nsw.gov.au

TO

https://sfobjtest.govnet.nsw.gov.au:8443/#/documents

0
Comment made 02-Feb-2018 by Kai Wilke 6973

Hi Rakesh,

to apply different rule for different URIs you may take a look the the sample below...

when HTTP_REQUEST {
    if { [string tolower [HTTP::host]] eq "sfobjtest.govnet.nsw.gov.au" } then {
        set low_uri [string tolower [HTTP::path]]
        if { $low_uri starts_with "/id:%20" } then {
            HTTP::respond 307 Location "https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/[findstr [HTTP::path] "/id:%20" 7 "/"]"
        } elseif { $low_uri starts_with "/docseach/id:%20" } then {
            HTTP::respond 307 Location "https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/[findstr [HTTP::path] "/docseach/id:%20" 16 "/"]"
        } elseif { $low_uri equals "/" } then {
            HTTP::respond 307 Location "https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/"
        }
    }
}

Cheers, Kai

0
Comment made 02-Feb-2018 by Stanislas Piron 10481

In the URI, you add a # character which is a fragment identifier.

a redirect to https://sfobjtest.govnet.nsw.gov.au:8443/#/documents/ will send only a / URI to the server. every character starting from # won't be sent to the web server by the browser.

0
Comment made 02-Feb-2018 by Kai Wilke 6973

Hi Stanislas,

some applications are designed like this by handling the fragment identifier either natively to jump to a specific <ID> tag or by using additional JScripts to make some magic happen in the background. So nothing unusual "per-se"...

Cheers, Kai

0
Comment made 03-Feb-2018 by Rakesh 12

Thanks Kai. It will help me a lot.

0
Comment made 03-Feb-2018 by Rakesh 12

Hi Kai,

I didn't understand these in your irule:-

1) findstr [HTTP::path] "/id:%20" 7 "/"

2) findstr [HTTP::path] "/id:%20" 16 "/"

Would it be possible for you to explain these bits?

Thanks, Rakesh

0
Comment made 21-Feb-2018 by Kai Wilke 6973

Hi Rakesh,

1) findstr [HTTP::path] "/id:%20" 7 "/"

Your https://sfobjtest.govnet.nsw.gov.au/docseach/id: (tokenised_string) sample contains a "whitespace" and the whitespace gots translated to %20 (aka. URI encoding). Thats why I've added the %20 to the [findstr] search patter and increased the skipcount to 7 to cutoff the %20 as well. So the command translates to: Parse the HTTP::path beginning from left, search for the first occourence of the string /id:%20 then skip 7 chars to the right (aka. to the end of /id:%20) and then remember everthing until the next / char.

2) findstr [HTTP::path] "/id:%20" 16 "/"

This command is not posted by me. I've posted [findstr [HTTP::path] "/docseach/id:%20" 16 "/"] which is basically the same as above, but with incresed skip count to include the added /docseach

Note: Be carefully how you cunstruct your samples ;-)

Cheers, Kai

0