we are making a website that takes a generated incoming link and forwards the user who is clicking on it to another website while saving a record of the action in our DB. I guess it’s basically what ad-services like AdSense do.
However, what is the best way to redirect the user?
I think html-meta-tag-redirects are out of question.
So what other options are there?
head :moved_permanently, :location => "http://www.domain.com/"
This one is a 301-redirect. The next one is a 302:
redirect_to "http://www.domain.com"
Are there any others? And which is best to use for our case? The links are highly-dynamic and change all the time.
We want to make sure we don’t violate any existing standards and of course we don’t want search-engines to tag us as spammers (which we are not, btw).
Thanks!
From the browser/end user point of view
are equivalent to
There are some minor technical differences which can lead to one choice rather than the other.
redirect_toexists as part of the routing architecture. You can pass URL options and the method automatically creates the final location, according to the app routing rules.On the opposite,
headis a lower-level API for dealing with response headers. It doesn’t care about the meaning of the headers you are passing to the response. It’s useful when you specifically need to work with headers. I wouldn’t use it to setup redirects.