Forum Discussion
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.
- Bajaja_370414Nimbostratus
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] …
- Vivek_377556Altostratus
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.
- StephNimbostratus
- Vivek_377556Altostratus
Thanks for your response. But using your query, there is an issue with syntax. I have tried your query. Its not working as well.
- StephNimbostratus
a too fast copy/past ;)
- StephNimbostratus
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_377556Altostratus
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.
- funduvalNimbostratus
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
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com