Ruby on Rails 301 redirection

前端 未结 2 1537
有刺的猬
有刺的猬 2021-02-15 11:49

I added slugs to some of the models, but because of SEO I need to do 301 redirection from old links: old:

http://host.com/foo/1

new:

         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-15 12:30

    For 301 redirection write this code in your controller:

    headers["Status"] = "301 Moved Permanently"

    redirect_to "http://host.com/foo/foo_slug" # in your case

    And for second question, use capitalise or down case if you mentioned hardcode url.

    Otherwise use ruby interpolation by putting whole url in string

提交回复
热议问题