How to make returnurl right after login from subdomain.

I use subdomains, when logging in at site.domain.com/login successful from another subdomain it redirects me to site.domain.com/[action]. How do I make it to redirect me to the right [controller].domain.com/[action]?

I tried to use $_SERVER[‘HTTP_REFERER’] but I got error:


Undefined index: HTTP_REFERER