Ruby on Rails 301 redirection

前端 未结 2 1548
有刺的猬
有刺的猬 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:06

    You should be able to redirect with status 301 by adding this to your controller action:

    redirect_to "http://host.com/foo/foo_slug", :status => 301
    

    See the API documentation for redirect_to for details.

    And there should be no problem with redirecting upper-cased URLs to lowercased versions, although this may be better handled by something at the HTTP server layer such as Apache mod_rewrite rules.

提交回复
热议问题