Forum Discussion

Vivek_377556's avatar
Vivek_377556
Icon for Altostratus rankAltostratus
Nov 22, 2018
Solved

irule to change url with preserving query parameters and include extra names in the final url

Hello,

 

I am new to irule. Below are the details of my requirement :

 

I have this url : http://xyz.com/test_check.do?test_id=XXX

 

I want to write an irule so that it will redirect/respond this to below and it will preserve all dynamic variables(XXX) during redirect or respong. http://xyz.com/testing/test_check.do?test_id=XXX

 

I have tried to write irule, but its not working :

 

when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/test_check"} { HTTP::respond 302 Location "https://xyz.com/testing/[URI::query [HTTP::uri]]" } }

 

Please provide suggestions/help me to resolve this.

 

Thanks in Advance !!!

 

  • I have tried below irule, added in the irule list and it worked correctly :

     

    when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/test_check.do?test_id="} { HTTP::redirect "https://xyz.com/testing[HTTP::uri]" } }

     

    Thanks you all for your responses.

     

8 Replies

    • Vivek_377556's avatar
      Vivek_377556
      Icon for Altostratus rankAltostratus

      Yes i want to preserve all parameters. I have tried your suggestion, its not working, getting 404 error.

       

      string tolower [HTTP::uri]] starts_with "/test_check"

       

      Should i change "starts_with" with some other function like contains ?

       

      Please suggest.

       

  • Thanks for your response. But using your query, there is an issue with syntax. I have tried your query. Its not working as well.

     

  • Steph's avatar
    Steph
    Icon for Nimbostratus rankNimbostratus

    This one Should work

     

    when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/test_check" } { HTTP::redirect "https://xyz.com/testing/[HTTP::uri]?[HTTP::query]" } }

     

  • I have tried below irule, added in the irule list and it worked correctly :

     

    when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/test_check.do?test_id="} { HTTP::redirect "https://xyz.com/testing[HTTP::uri]" } }

     

    Thanks you all for your responses.

     

    • funduval's avatar
      funduval
      Icon for Nimbostratus rankNimbostratus

      Hi Vivek,

      So glad you got this working (now ages ago!) I was wondering, if you still check in here, could I implement this same solution with a longer path & switching the hostname, such as:

      when HTTP_REQUEST {if {[string tolower [HTTP::uri]] starts_with "/beginningpath/nextlevel/nextlevel/MyAccountLogin.js?client_id="} { HTTP::redirect "https://a-totally-new-hostname/[HTTP::uri]" }}

      I need to preserve & forward the incoming client id which is different every time.

      Thanks,

      Funda