Reputation: 407
I've made mistake and allowed two different routes pointing at same place. Now I've got troubles with duplicated content.
News could be viewed in two ways: http://website.com/posts/321 and http://website.com/news/this-is-title/321
I want to fix this mess and my idea is to check by what link user is coming. For example if someone will came through http://website.com/posts/321 I would like to redirect visitor to correct route: http://website.com/news/this-is-title/321
My very first idea is to validate request url at Post controller and then in if statement decide about redirecting or simply displaying proper view. Is it good conception?
Upvotes: 0
Views: 459
Reputation: 26997
In your posts_controller.rb
show:
def show
return redirect_to post_path(params[:id]) if request.fullpath.match /(your regex)/i, :status => 301, :notice => 'This page has been permanently moved'
@post = Post.find(...)
end
Upvotes: 0
Reputation: 34613
I don't think you should bother, take a look at canonical url's if you're worried about SEO
Upvotes: 0
Reputation: 115531
I think it's not the best fit.
You should do this at routes level using the redirect methods.
Upvotes: 1