Next.js URL Redirection
Unanswered
Asian black bear posted this in #help-forum
Asian black bearOP
Hello, I want to redirect one URL in Next.js
Source URl: /shop-cars-for-sale/demo?make=RENAULT
Destination URL: /used-cars/demo
I'm redirecting this URL in the next.cinfig.js file like this,
module.exports = {
async redirects() {
return [
{
source: '/shop-cars-for-sale/demo/?\make=:make',
destination: '/used-cars/demo',
permanent: true,
},
]
},
}
Also tried:-
module.exports = {
async redirects() {
return [
{
source: '/shop-cars-for-sale/demo',
destination: '/used-cars/demo',
has: [
{
type: 'query',
key: 'make',
},
],
permanent: true,
},
];
},
};
It's redirecting me to /used-cars/demo page but it also contains query params and I wanna ignore query params in the destination URL.
So how can I do that? Is there any other way to do this?
Source URl: /shop-cars-for-sale/demo?make=RENAULT
Destination URL: /used-cars/demo
I'm redirecting this URL in the next.cinfig.js file like this,
module.exports = {
async redirects() {
return [
{
source: '/shop-cars-for-sale/demo/?\make=:make',
destination: '/used-cars/demo',
permanent: true,
},
]
},
}
Also tried:-
module.exports = {
async redirects() {
return [
{
source: '/shop-cars-for-sale/demo',
destination: '/used-cars/demo',
has: [
{
type: 'query',
key: 'make',
},
],
permanent: true,
},
];
},
};
It's redirecting me to /used-cars/demo page but it also contains query params and I wanna ignore query params in the destination URL.
So how can I do that? Is there any other way to do this?
3 Replies
Ray
the other way is create a page at
app/shop-cars-for-sales/demo/page.tsx
then do export default function Page() {
permanentRedirect('/used-cars/demo')
}
Asian black bearOP
Ok thanks, but is there any possibility to remove query parameter using redirection inside next.config.js file?
Ray
guess not