Next.js URL Redirection
Unanswered
Asian black bear posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
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
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
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')
}
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Asian black bearOP
Ok thanks, but is there any possibility to remove query parameter using redirection inside next.config.js file?
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
guess not