Forum Discussion

F5-KHAN's avatar
F5-KHAN
Icon for Nimbostratus rankNimbostratus
Jun 27, 2019

irule to remove part of uri and combine uri

Hi All,

 

I am looking for irule to achieve below result.

 

1. stg.gr.com/content/ga/en/page.html  --- content uri should be removed and ga/en should merged in form of /en-ga/

to be 301 redirected to stg.gr.com/en-qa/page.html

 e.g. stg.gr.com/content/ga/en/homepage.html to stg.gr.com/en-ga/homepage.html

 e.g. stg.gr.com/content/fr/en/homepage.html to stg.gr.com/en-fr/homepage.html

 e.g. stg.gr.com/content/ka/en/homepage.html to stg.gr.com/en-ka/homepage.html

similar like /ga/ there are other uris

 

Appreciate help .

Thanks in advance.

4 Replies

  • Try this

    when HTTP_REQUEST {
        if {[HTTP::uri] starts_with "/content"} {
            set field2 [getfield [HTTP::uri] / 3]
            set field3 [getfield [HTTP::uri] / 4]
            set mergedFields ${field3}-${field2}
            set removeContent [string map [list "/content" ""][HTTP::uri]]
            set newUri [string map [list "${field2}/${field3}" $mergedFields][HTTP::uri]]
     
            HTTP::redirect https://[HTTP::host]$newUri
        }
    }
  • Try this code:

     

    when HTTP_REQUEST {
        if {[scan $uri {/content/%[^/]/%[^/]/%s} language1 language2 other] == 3 } {
            HTTP::respond 301 Location "/$language2-$language1/$other"
        }
    }