Next Rewrite to external url without updating the URL
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hi, is it possible to have a next rewrite in next.config where i want to rewrite it to a external site but without updating the url in browser?
If i'm rewriting the url to the app, it is keeping the url but when im trying to rewrite it to external url, it is updating the url.
Code:
If i'm rewriting the url to the app, it is keeping the url but when im trying to rewrite it to external url, it is updating the url.
Code:
rewrites: async () => {
return [
{
source: "/test1",
destination: "https://google.com", // url in browsers gets changed to google.com
},
{
source: "/test2",
destination: "/testing", // url stays the same i.e /test2
},
];
},
1 Reply
Siamese Crocodile
The rewrite technically works as you expect it to be, but google.com answers with a 301 redirect, that next passes to the browser as is.
You can see the same behaviour, when opening the URL you used in the browser directly; It will redirect to https://www.google.com (including www. and without trailing slash.
If you use that URL instead, like this:
{
source: '/test1',
destination: 'https://www.google.com',
},
The site will display right under your rewritten URL!
You can see the same behaviour, when opening the URL you used in the browser directly; It will redirect to https://www.google.com (including www. and without trailing slash.
If you use that URL instead, like this:
{
source: '/test1',
destination: 'https://www.google.com',
},
The site will display right under your rewritten URL!