Forum Discussion

ras2018_335513's avatar
ras2018_335513
Icon for Nimbostratus rankNimbostratus
Dec 17, 2018

URI Redirect Coveo Index Test

Looking for assistance with a uri redirect where certain elements of the URI are subject to change, but the remaining items stay the same.

 

As an example:

 

https://api-itg-1.testdomain.com/abc-apitest-v1-itg/api

 

needs to map to:

 

https://api-itg-1.testdomain.com/apitest/v1/api

 

The only elements that would change are the placeholders used by "apitest" and "v1" above. Everything after /v1/ in the example above should remain the same.

 

4 Replies

  • ras,

     

    From my understanding, the iRule you are requesting ignores 'abc' and 'itg' so I have no included any handling for that in my example code. This iRule will only activate if the uri has more than one slash and if it doesnt end with a slash to prevent calculation errors.

     

    when HTTP_REQUEST
    {
        if {([string trimleft [HTTP::path] "/"] contains "/") and not ([HTTP::path] ends_with "/")}
        {
            set uri_list [split [HTTP::path] /]
            set orig_uri [lindex $uri_list 1] 
            set uri_elements [split $orig_uri -]
            set new_uri [lindex $uri_elements 1]/[lindex $uri_elements 2]
            lset uri_list 1 $new_uri
            log local0. [join $uri_list /]
            HTTP::uri [join $uri_list /]
        }
    }

    Hope this helps.

     

  • dluzzi's avatar
    dluzzi
    Icon for Nimbostratus rankNimbostratus

    Hello,

     

    You can probably use the string map within an irule. Not sure if the rough syntax I have below is correct. You can read more here: https://clouddocs.f5.com/api/irules/HTTP__path.html

     

        "api-itg-1.testdomain.com" {
            switch -glob [string tolower [HTTP::uri]] {
                "/apitest/*"  {
                    HTTP::path [string map {/abc-apitest-v1-itg /apitest} [HTTP::path]]
                    }
                    }
                    }
    
  • Hi Guy,

    Use this irule:
    when HTTP_REQUEST {
    if {[HTTP::host] eq "api-itg-1.testdomain.com" and [HTTP::path] starts_with "/abc-" } {
        set firstPartOfURI [getfield [HTTP::uri] "/" 2]
        set lastPartOfURI [findstr [string range [HTTP::uri] 2 end] / 1]
        set firstPath [getfield firstPartOfURI "-" 2]
        set secondPath [getfield firstPartOfURI "-" 3]
        HTTP::redirect "/${firstPath}/${secondPath}/${lastPartOfURI}"
    }
    }
    
  • ignore the title change everyone (where I added Coveo Index Test)...we are tuning some search issues