2014-08-29 03:09:36 +08:00
|
|
|
class PermalinksController < ApplicationController
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :check_xhr, :preload_json
|
2014-08-29 03:09:36 +08:00
|
|
|
|
|
|
|
def show
|
2015-07-22 11:40:45 +08:00
|
|
|
url = request.fullpath
|
2015-04-24 04:45:28 +08:00
|
|
|
|
2014-09-11 01:58:52 +08:00
|
|
|
permalink = Permalink.find_by_url(url)
|
2015-04-24 04:45:28 +08:00
|
|
|
|
|
|
|
raise Discourse::NotFound unless permalink
|
|
|
|
|
|
|
|
if permalink.external_url
|
|
|
|
redirect_to permalink.external_url, status: :moved_permanently
|
|
|
|
elsif permalink.target_url
|
2015-10-13 04:48:32 +08:00
|
|
|
redirect_to permalink.target_url, status: :moved_permanently
|
2014-08-29 03:09:36 +08:00
|
|
|
else
|
|
|
|
raise Discourse::NotFound
|
|
|
|
end
|
|
|
|
end
|
2015-04-24 04:45:28 +08:00
|
|
|
|
2014-08-29 03:09:36 +08:00
|
|
|
end
|