Redirect not working next.config.js
Answered
Palomino posted this in #help-forum
PalominoOP
I'm fairly new to nextjs. I'm having an issue where I have a redirect in the
Is this an issue with the parenthesis in the source url?
next.config.js file but it's not working. It's not going to the destination url.Is this an issue with the parenthesis in the source url?
const nextConfig = {
async redirects() {
return [
{
source: "/douglas-pollina(p)-symington",
destination: "/douglas-pollina-symington",
permanent: true,
statusCode: 301
}
]
}
}Answered by riský
yeah parenthesis are an issue as its thinking regex mode, but you should be able to escape them and it should work
https://nextjs.org/docs/app/api-reference/next-config-js/redirects#regex-path-matching
\\(p\\)https://nextjs.org/docs/app/api-reference/next-config-js/redirects#regex-path-matching
4 Replies
@Palomino I'm fairly new to nextjs. I'm having an issue where I have a redirect in the `next.config.js` file but it's not working. It's not going to the destination url.
Is this an issue with the parenthesis in the source url?
js
const nextConfig = {
async redirects() {
return [
{
source: "/douglas-pollina(p)-symington",
destination: "/douglas-pollina-symington",
permanent: true,
statusCode: 301
}
]
}
}
yeah parenthesis are an issue as its thinking regex mode, but you should be able to escape them and it should work
https://nextjs.org/docs/app/api-reference/next-config-js/redirects#regex-path-matching
\\(p\\)https://nextjs.org/docs/app/api-reference/next-config-js/redirects#regex-path-matching
Answer
PalominoOP
Awesome!! Thanks a lot
@Palomino Awesome!! Thanks a lot
np, enjoy your building of site!
Philippine Crocodile
you can do it by middleweare.