Next.js Discord

Discord Forum

Change all redirects from 308 to 301

Unanswered
Rose-breasted Grosbeak posted this in #help-forum
Open in Discord
Rose-breasted GrosbeakOP
I have a requirement from a customer SEO to redirect all pages from 308 to 301. Project is developed in NextJS 13 with page folder. I've handled most of the cases (old pages to new pages after migration) in middleware.ts using

return NextResponse.redirect(new URL(address.destination), { status: 301 });

General page structure is following: xyz.com/offer/:brand/:model/

The problem is that when user enters xyz.com//offer or xyz.com///offer (multiple slashes) it redirects to xyz.com/offer with 308 code.

Do you have any idea how to solve this?

18 Replies

using the default nextjs redirections, you can't use those...
you should use middlewire to have full control, wait i missunderstood
and whats wrong with /// being redirected/simplified to just /?
+ what are you redirecting...? pages to what? (and what url change has occured), if it is app dir ,then have you changed the format of urls?
Rose-breasted GrosbeakOP
I am redirecting pages, when redirecting /// to / i need a status 301 not 308
and basically, I'm redirecting pages to pages, for example xyz.com/offer//audi to xyz.com/offer/audi
and why is that... 308 is basically the same as 301 except that 308 only does GET requests
Rose-breasted GrosbeakOP
that is unfortunately customers seo requirement, they're really stubborn, I tried to explain that but without any success
im pretty sure no seo says that it is a valid thing... but i see your frustration 😭
but as that redirect is probably handled from nextjs before the middlewire, idk if you can do much
Rose-breasted GrosbeakOP
yeah, I've never thought it will be a problem, but as you said they will have to live with that 😄
Im pretty sure you cant change that and the explanation is in the docs
Also i dont know what those seo guys are talking about tbh
the only way is to make a proxy before nextjs server, but you are getting way overkil for a non-issue
Rose-breasted GrosbeakOP
proxy? do you think it will take a lot of time to make?
and not needed
your only realistic option it to tell them that it doesn't hurt seo
there is no-where that says google thinks of them diferently
If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a permanent server-side redirect whenever possible. This is the best way to ensure that Google Search and people are directed to the correct page. The 301 and 308 status codes mean that a page has permanently moved to a new location.
https://developers.google.com/search/docs/crawling-indexing/301-redirects