Redirecting to RoR: which one to use from redirect_to and head: move_permanently?

we create a website that takes the created inbound link and forwards the user who clicks on it to another website, keeping a record of the action in our database. I assume that these are mainly advertising services such as AdSense.

However, what is the best way to redirect a user?

I think html-meta-tag-redirects is out of the question.

So what are the other options?

head :moved_permanently, :location => "http://www.domain.com/" 

This is a 301 redirect. Next is 302:

 redirect_to "http://www.domain.com" 

Are there any others? And what is the best use for our business? Links are very dynamic and constantly changing.

We want to make sure that we do not violate existing standards, and, of course, we do not want search engines to mark us as spammers (which we do not know, by the way).

Thanks!

+4
source share
1 answer

In terms of browser / end user

 redirect_to "http://www.domain.com" redirect_to "http://www.domain.com", :status => 302 redirect_to "http://www.domain.com", :status => 301 

are equivalent

 head 301, :location => "http://www.domain.com/" head 302, :location => "http://www.domain.com/" 

There are some minor technical differences that may lead to one option and not another.

redirect_to exists as part of the routing architecture. You can pass URL parameters, and the method automatically creates the final location in accordance with the applicationโ€™s routing rules.

 redirect_to root_url, :status => 302 redirect_to { :controller => "main", :action => "index" }, :status => 302 

In contrast, head is a lower-level API for working with response headers. It doesnโ€™t care about the meaning of the headers you provide in response. This is useful when you need to work with headers. I would not use it to configure redirection.

+6
source

Source: https://habr.com/ru/post/1308341/


All Articles