开发者

How do I write a route that is SEO friendly in rails?

开发者 https://www.devze.com 2023-01-10 11:10 出处:网络
I am changing my site over fr开发者_如何转开发om Google App Engine to rails and I would like to keep my place in google search. Currently my site uses a URL /page?pid=microsoft-interview-questions to

I am changing my site over fr开发者_如何转开发om Google App Engine to rails and I would like to keep my place in google search. Currently my site uses a URL /page?pid=microsoft-interview-questions to access the Microsoft subsection of interview questions. How would I create a route that can send this to '/tags/:id' where :id would be microsoft in this case?


In addition to josh's answer I'll put this here for formatting:

# your controller

def show
  @subject = Subject.find my_stripped_id


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


something like this should work (in routes.rb):

map.connect '/page?pid=:number', :controller => 'tags', :action => 'show'

see routes reference

0

精彩评论

暂无评论...
验证码 换一张
取 消