- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我们正在制作一个网站,该网站采用生成的传入链接并将点击它的用户转发到另一个网站,同时在我们的数据库中保存操作记录。我想这基本上就是像 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/
我有一个简单的模型和 Controller 。让我们以新西兰人为例: def index @kiwis = Kiwi.all end def destroy kiwi = Kiwi.f
我怀疑这两个命令之间是否存在差异,当我想在 Rails 中创建没有 View 的操作时,我一直使用 redirect_to之后没有任何返回,我从来没有遇到任何问题,但直到我忘记放置 redirect_
我的代码是这样的: def index @monkeys = Monkey.where(owner: current_user) end def new @monkey = Monkey.ne
我有一个 Controller ,可以在特定条件下在特定点重定向。当我将参数传递给我的 Controller 规范(使用最新的 RSpec)中的规范辅助方法以触发这些条件时,我得到一个 ActionV
我的应用程序中有很长的表单,所以我设置了一个 _new_form.html.erb这是在我的 new.html.erb 中呈现的.在用户更新此表单并通过一些基本验证后,我希望它们被重定向到 edit.
代码是什么 redirect_to @user 在 Controller 方法中使用时,是指在 Rails 中吗? 它究竟重定向到哪里?它是重定向到用户 Controller (如果是, Contro
我有一个 Rails 应用程序,它有一个在 iframe 中呈现的表单,从创建操作我想从 iframe 中 redirect_to 并重新呈现整个页面而不是在iframe. 我很好奇有什么想法可以实现
我正在尝试根据提交的表单上的参数重定向到一个位置。 如果 params[:route] = group ,我想重定向到 groups_path。 我尝试了以下方法来重定向,但很明显,groups_pa
def confirm_invite_new_tutor redirect_with_msg = false @game_school = GameSchool.find(params
我在使用 rails 时遇到了一点问题,我希望能够做这样的事情来避免多次重定向: def render_not_found not_found end private def not_foun
我是菜鸟 redirect_to users_url, notice: 'Succeed.' 然后我添加了一条消息,但它失败了: redirect_to users_url, notice: 'Su
我的付款表单中有一个隐藏的输入,如下所示: "> " /> 支付后我会这样使用它: header("location: " . $_GET['redirect_to']); 一切正
我正在学习 Rails 并且遇到了 Rspec 的问题。我对 Controller 进行了以下测试: describe PostsController, "creating a new post" d
我试图在资源创建后显示它。 路线.rb resources :eco_systems do member do get 'new' post 'create'
我见过的最奇怪的事情。 在 Controller 中,我尝试重定向以将用户发送到另一个网站: redirect_to "http://google.com" --> This works. 但是,如果
Turbolinks 在整个应用程序中运行。我需要在某个场景中在 create 方法中重新加载页面。 这会重定向到正确的页面,但不会重新加载页面: redirect_to convos_path 这会
我已经尝试查看其他答案,但我似乎无法弄清楚为什么我的重定向不起作用。 所以我在 Rails 3.1 中使用 Devise,我正在制作一个购物网站。除非已登录,否则不允许访问者将商品添加到购物车。这就是
在我的 rails 应用程序中,我有一个学生模型和一个 material_student。在学生登录后,我会将其重定向到一个页面,让他可以选择在两个“编辑” View 之间进行选择。第一个由stude
我在 The Rails 3 Way 一书中看到了一个例子,它说 redirect_to post 这是否因为 post 而有什么特殊含义? , 或者如果它只是一个示例和 post 的糟糕选择只是一个
试图弄清楚为什么我的 nil 检查在调用没有参数的方法或不产生记录的参数 ID 时失败。 @game = Game.where(:id => params[:id]).first if @game.n
我是一名优秀的程序员,十分优秀!