fix: #8549 send 308 Permanent Redirect on topic/category shortlinks

v1.18.x
Julian Lam 5 years ago
parent def16f9e97
commit 68f8d6e3a1

@ -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;

@ -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));
}
};

@ -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') {

Loading…
Cancel
Save