From a2b1c7e66c0d516a8043b46191fae41650087843 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Fri, 5 Jun 2009 09:02:05 -0500 Subject: [PATCH] HTTP Redirects for Redirected Pages If a page isn't found, but there is a page that redirects for it, don't show a 404! --- app/controllers/wiki_controller.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 4407be0b..4575bbb5 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -229,9 +229,17 @@ class WikiController < ApplicationController @page_name ||= 'HomePage' @page ||= wiki.read_page(@web_name, @page_name) @link_mode ||= :publish - render(:text => "Page '#{@page_name}' not found", :status => 404, :layout => 'error') and return unless @page - - @renderer = PageRenderer.new(@page.revisions.last) + if @page + @renderer = PageRenderer.new(@page.revisions.last) + else + real_page = WikiReference.page_that_redirects_for(@web, @page_name) + if real_page + flash[:info] = "Redirected from \"#{@page_name}\"." + redirect_to :web => @web_name, :action => 'published', :id => real_page + else + render(:text => "Page '#{@page_name}' not found", :status => 404, :layout => 'error') + end + end end def revision @@ -311,7 +319,13 @@ class WikiController < ApplicationController end else if not @page_name.nil? and @page_name.is_utf8? and not @page_name.empty? - redirect_to :web => @web_name, :action => 'new', :id => @page_name + real_page = WikiReference.page_that_redirects_for(@web, @page_name) + if real_page + flash[:info] = "Redirected from \"#{@page_name}\"." + redirect_to :web => @web_name, :action => 'show', :id => real_page + else + redirect_to :web => @web_name, :action => 'new', :id => @page_name + end else render :text => 'Page name is not specified', :status => 404, :layout => 'error' end