【问题标题】:How do I write a route that is SEO friendly in rails?如何在 Rails 中编写对 SEO 友好的路线?
【发布时间】:2011-03-24 10:41:06
【问题描述】:

我正在将我的网站从 Google App Engine 更改为 rails,并且我想保留我在 Google 搜索中的位置。目前,我的网站使用 URL /page?pid=microsoft-interview-questions 访问 Microsoft 面试问题小节。我将如何创建一个可以将其发送到 '/tags/:id' 的路由,在这种情况下 :id 将是微软?

【问题讨论】:

  • 是保留现有路由,还是发送到“标签”?还是两者兼而有之?
  • 不太清楚你在问什么。你想收到这个:"/tags/page?pid=microsoft-interview-questions" 和 "page?pid=microsoft-interview-questions" 作为 :id 参数?
  • 抱歉不清楚,我希望/page?pid=microsoft-interview-questions 转到 :controller => 标签, :action => 显示标题为 microsoft 的标签。
  • 看来你可以在 Google App Engine 上部署 rails...stackoverflow.com/questions/3278745/…

标签: ruby-on-rails seo custom-routes


【解决方案1】:

除了 josh 的回答,我将把它放在这里进行格式化:

# your controller

def show
  @subject = Subject.find my_stripped_id


private
def my_stripped_id
  params[:id].sub(/-interview-questions/, '')
end

【讨论】:

  • 这会处理提取 id 的逻辑部分。不过,似乎是因为 ?它以 pid 而不是 id 的形式传递参数
【解决方案2】:

这样的东西应该可以工作(在 routes.rb 中):

map.connect '/page?pid=:number', :controller => '标签', :action => '显示'

routes reference

【讨论】:

  • 唯一的问题是我不知道如何解析标签名称后面的“-interview-questions”。
猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 2019-05-29
  • 2012-08-14
  • 2020-08-10
  • 1970-01-01
  • 2016-09-22
  • 1970-01-01
相关资源
最近更新 更多