2014-08-28 15:09:36 -04:00
|
|
|
class PermalinksController < ApplicationController
|
|
|
|
skip_before_filter :check_xhr, :preload_json
|
|
|
|
|
|
|
|
def show
|
2015-07-21 23:40:45 -04:00
|
|
|
url = request.fullpath
|
2015-04-23 16:45:28 -04:00
|
|
|
|
2014-09-10 13:58:52 -04:00
|
|
|
permalink = Permalink.find_by_url(url)
|
2015-04-23 16:45:28 -04:00
|
|
|
|
|
|
|
raise Discourse::NotFound unless permalink
|
|
|
|
|
|
|
|
if permalink.external_url
|
|
|
|
redirect_to permalink.external_url, status: :moved_permanently
|
|
|
|
elsif permalink.target_url
|
2015-04-19 23:35:53 -04:00
|
|
|
redirect_to "#{Discourse::base_uri}#{permalink.target_url}", status: :moved_permanently
|
2014-08-28 15:09:36 -04:00
|
|
|
else
|
|
|
|
raise Discourse::NotFound
|
|
|
|
end
|
|
|
|
end
|
2015-04-23 16:45:28 -04:00
|
|
|
|
2014-08-28 15:09:36 -04:00
|
|
|
end
|