I have qr codes that have been published with an old url. I need to redirect that old url to a new external url. I have just revamped this project by incorporating Nuxtjs. I have tried using the redirect middleware, but no success. Can somebody help me?
I want my old url, 'example.io/guestbooklet/1' to redirect to 'https://dashboard.example.io/guestbooklet/1'
middleware/redirects.js
export default function(req, res, next) {
const redirects = [
{
from: "/guestbooklet/:property_id",
to: "https://dashboard.example.io/guestbooklet/:property_id"
}
]
const redirect = redirects.find((r) => r.from === req.url)
console.log('Redirecting', redirect)
if (redirect) {
res.writeHead(301, { Location: redirect.to })
res.end()
} else {
next()
}
}
nuxt.config.js
serverMiddleware: [
'~/middleware/redirects.js'
],