Redirect users who request records that no longer exist. Search engines may have pages indexed for resources that have been deleted.

posts_controller.rb
1
2
3
4
5
6
7
8
9
10
11
def show
  @link = Link.find(params[:id])

  respond_to do |format|
      format.html
      format.json { render :json => @post }
  end

  rescue ActiveRecord::RecordNotFound
    redirect_to root_url
end

Instead of returning 404 pages, you can redirect visitors to an index page where they can find something useful.

Comments