redirect to original uri

I have an application running through APM that prompts the user for login when connecting. This works great on a general request, but not when going to a specific link within the app.

If a user goes to https://app.company.com, a session is established, he is prompted for login, and then he goes to the main page of the app (the full url is now https://app.company.com/). However, if you are given a link, say http://app.company.com/xyz, after establishing a session and logging in, you are taken to the main page (https://app.company.com/) rather than to https://app.company.com//xyz.

Is there a way to configure an irule to caputer the /xyz of the original request, and then after the APM session is established, allow the user to continue on to the original request?

You should be able to store the original request in a cookie.

Any tips on how to accomplish this with a cookie?