cancel
Showing results for 
Search instead for 
Did you mean: 

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

Vivek_377556
Altostratus
Altostratus

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 !!!

 

1 ACCEPTED SOLUTION

Vivek_377556
Altostratus
Altostratus

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.

 

View solution in original post

8 REPLIES 8

Bajaja_370414
Nimbostratus
Nimbostratus

Hi, result of [URI::query [HTTP::uri]] in your case is just test_id=XXX. But you want to preserve all parts of the path. Is it correct? Try this: https://xyz.com/testing[HTTP::uri] …

 

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.

 

Steph
Nimbostratus
Nimbostratus

try this after the "if"

 

{ HTTP::redirect "https://xyz.com/testing/[HTTP::uri]?[URI::query]" }

 

Vivek_377556
Altostratus
Altostratus

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
Nimbostratus
Nimbostratus

a too fast copy/past 😉

 

Steph
Nimbostratus
Nimbostratus

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]" } }

 

Vivek_377556
Altostratus
Altostratus

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.

 

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