From ae028a5bb1d6d882a82fd4707386c6ef8eae044b Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 23 Apr 2015 16:45:28 -0400 Subject: [PATCH] FIX: support for redirects to external url in permalinks table was broken --- app/controllers/permalinks_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/permalinks_controller.rb b/app/controllers/permalinks_controller.rb index 3b243d955ee..4211c85fb56 100644 --- a/app/controllers/permalinks_controller.rb +++ b/app/controllers/permalinks_controller.rb @@ -3,11 +3,18 @@ class PermalinksController < ApplicationController def show url = request.fullpath[1..-1] + permalink = Permalink.find_by_url(url) - if permalink && permalink.target_url + + raise Discourse::NotFound unless permalink + + if permalink.external_url + redirect_to permalink.external_url, status: :moved_permanently + elsif permalink.target_url redirect_to "#{Discourse::base_uri}#{permalink.target_url}", status: :moved_permanently else raise Discourse::NotFound end end + end