gpt4 book ai didi

ruby-on-rails - 在 RoR : Which one to use out of redirect_to and head :moved_permanently? 中重定向

转载 作者:数据小太阳 更新时间:2023-10-29 07:29:33 25 4
gpt4 key购买 nike

我们正在制作一个网站,该网站采用生成的传入链接并将点击它的用户转发到另一个网站,同时在我们的数据库中保存操作记录。我想这基本上就是像 AdSense 这样的广告服务所做的。

但是,重定向用户的最佳方式是什么?

我认为 html-meta-tag-redirects 是不可能的。

那么还有哪些选择呢?

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

这是一个 301 重定向。下一个是 302:

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

还有其他的吗?哪个最适合我们的案例?这些链接是高度动态的并且一直在变化。

我们想确保我们不违反任何现有标准,当然我们不希望搜索引擎将我们标记为垃圾邮件发送者(顺便说一句,我们不是)。

谢谢!

最佳答案

从浏览器/最终用户的角度来看

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

相当于

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

存在一些细微的技术差异,可能会导致一种选择而不是另一种选择。

redirect_to 作为路由架构的一部分存在。您可以传递 URL 选项,该方法会根据应用路由规则自动创建最终位置。

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

相反,head 是用于处理响应 header 的低级 API。它不关心您传递给响应的 header 的含义。当您特别需要使用标题时,它很有用。我不会用它来设置重定向。

关于ruby-on-rails - 在 RoR : Which one to use out of redirect_to and head :moved_permanently? 中重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2736461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com