0
我有一個像/users/HGB8J/
的路線,我希望做一個301重定向,如果用戶不使用僅大寫字母爲userTag
。我試圖寫一箇中間件能保證大寫的userTag
多路徑,如下圖所示。重定向到URL請求與修改後的參數
我的問題:
我怎樣才能做一個重定向到 「原始地址」 只是一個修改後的參數(在這種情況下,大寫userTag
)
function ensureTagIsUppercased(req, res, next) {
let userTag = req.params.userTag
if(userTag === userTag.toUpperCase())
next()
// How can I build the same URL just with the uppercased userTag?
let url = ''
return res.redirect(301, url)
}
router.get('/:userTag', ensureTagIsUppercased, profile)
router.get('/:userTag/refresh', ensureTagIsUppercased, refreshProfile)
例子:
用戶請求=>https://example.com/users/HGB8J/請求可以通過
個用戶請求=>https://example.com/users/hgB8J/應該被重定向到=>https://example.com/users/hgB8J/refresh應該被重定向到https://example.com/users/HGB8J/refresh