HTTP redirects tell search engines and users that content has moved to a new location. When implemented correctly, they preserve your SEO value while ensuring users find your content.
✅ Good for:
❌ Don't use for:
In Vue applications, implement redirects at the server level:
// example using Express
app.get('/old-page', (req, res) => {
res.redirect(301, '/new-page')
})
// Pattern matching
app.get('/blog/:slug', (req, res) => {
res.redirect(301, `/articles/${req.params.slug}`)
})
// example using Vite SSR middleware
app.use((req, res, next) => {
if (req.path === '/old-page') {
return res.redirect(301, '/new-page')
}
next()
})
301: Permanent redirect - transfers SEO value302: Temporary redirect - keeps SEO value on original URL307: Temporary redirect (preserves HTTP method)308: Permanent redirect (preserves HTTP method)For SEO, 301 redirects are most common as they pass ranking signals to the new URL.
// example using Express
app.use((req, res, next) => {
const host = req.get('host')
// Redirect old domain to new
if (host === 'old-domain.com') {
return res.redirect(301, `https://new-domain.com${req.path}`)
}
next()
})
// Single redirects
app.get('/old', (req, res) => {
res.redirect(301, '/new')
})
// Pattern matching
app.get('/blog/:slug', (req, res) => {
res.redirect(301, `/articles/${req.params.slug}`)
})
// Parameter mapping
app.get('/products/:id', (req, res) => {
res.redirect(301, `/shop/${req.params.id}`)
})
app.use((req, res, next) => {
if (req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect(301, `https://${req.get('host')}${req.path}`)
}
next()
})
Learn more about HTTPS in our security guide.
app.use((req, res, next) => {
const host = req.get('host')
// Redirect non-www to www
if (!host.startsWith('www.')) {
return res.redirect(301, `https://www.${host}${req.path}`)
}
next()
})
Bad:
/old → /interim → /final
Good:
/old → /final
/interim → /final
When moving to HTTPS, update all resource URLs:
app.use((req, res, next) => {
// Redirect HTTP to HTTPS
if (req.headers['x-forwarded-proto'] === 'http') {
return res.redirect(301, `https://${req.get('host')}${req.path}`)
}
next()
})
Avoid circular redirects:
// ❌ Bad
app.get('/page-a', (req, res) => res.redirect(301, '/page-b'))
app.get('/page-b', (req, res) => res.redirect(301, '/page-a'))
// ✅ Good
app.get('/page-a', (req, res) => res.redirect(301, '/final'))
app.get('/page-b', (req, res) => res.redirect(301, '/final'))
If you're using Nuxt, check out Nuxt SEO which handles much of this automatically.