Node.js based forum software built for the modern web
fix: #8549 send 308 Permanent Redirect on topic/category shortlinks
Julian Lam68f8d6e3a115
diff --git a/src/controllers/category.js b/src/controllers/category.jsindex 907bdbc0fd..99f2d241a2 100644--- a/src/controllers/category.js+++ b/src/controllers/category.js@@ -39,7 +39,7 @@ categoryController.get = async function (req, res, next) {}if (!res.locals.isAPI && (!req.params.slug || categoryFields.slug !== cid + '/' + req.params.slug) && (categoryFields.slug && categoryFields.slug !== cid + '/')) {- return helpers.redirect(res, '/category/' + categoryFields.slug);+ return helpers.redirect(res, '/category/' + categoryFields.slug, true);}const topicCount = categoryFields.topic_count;diff --git a/src/controllers/helpers.js b/src/controllers/helpers.jsindex 5f560038d7..7ac17130f4 100644--- a/src/controllers/helpers.js+++ b/src/controllers/helpers.js@@ -151,11 +151,11 @@ helpers.notAllowed = async function (req, res, error) {}};-helpers.redirect = function (res, url) {+helpers.redirect = function (res, url, permanent) {if (res.locals.isAPI) {res.set('X-Redirect', encodeURI(url)).status(200).json(url);} else {- res.redirect(nconf.get('relative_path') + encodeURI(url));+ res.redirect(permanent ? 308 : 307, nconf.get('relative_path') + encodeURI(url));}};diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex e777aded8a..26c1b5715f 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -44,7 +44,7 @@ topicsController.get = async function getTopic(req, res, callback) {}if (!res.locals.isAPI && (!req.params.slug || topicData.slug !== tid + '/' + req.params.slug) && (topicData.slug && topicData.slug !== tid + '/')) {- return helpers.redirect(res, '/topic/' + topicData.slug + (postIndex ? '/' + postIndex : '') + (currentPage > 1 ? '?page=' + currentPage : ''));+ return helpers.redirect(res, '/topic/' + topicData.slug + (postIndex ? '/' + postIndex : '') + (currentPage > 1 ? '?page=' + currentPage : ''), true);}if (postIndex === 'unread') {