mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	fix: #8549 send 308 Permanent Redirect on topic/category shortlinks
This commit is contained in:
		| @@ -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 + '/')) { | 	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; | 	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) { | 	if (res.locals.isAPI) { | ||||||
| 		res.set('X-Redirect', encodeURI(url)).status(200).json(url); | 		res.set('X-Redirect', encodeURI(url)).status(200).json(url); | ||||||
| 	} else { | 	} 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 + '/')) { | 	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') { | 	if (postIndex === 'unread') { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user