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 : .xyz Domain Names | Join Generation XYZ

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. .xyz Domain Names | Join Generation XYZ

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

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.

try this after the “if”

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

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

a too fast copy/past :wink:

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.

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