how to get referrer from a redirected url

Prabesh Shrestha picture Prabesh Shrestha · Jan 17, 2012 · Viewed 10.5k times · Source

I have an url

domain.com/a

which redirects to

domain.com/controller/action/a .

How do I get the referrer (i.e domain.com/a) in my action for domain.com/controller/action/a ?

One option was to add the referring domain as a parameter .

domain.com/controller/action/a?referral=domain.com/a .

Is there a way to get the referrer without passing old referrer as a parameter. Like we would get from **request.referrer**. request.referrer doesn't seem to work with redirected urls.

I am using Ruby on Rails for my development.

Answer

okliv picture okliv · Apr 10, 2012

I store the referrer path in the session right before redirection

session[:referrer]=url_for(params)

and then use it where I need it via session[:referrer].