Next.js Discord

Discord Forum

unable to rewrite URL

Answered
Naeemgg posted this in #help-forum
Open in Discord
I want to rewrite URL from /en/dashboard to /.

const nextConfig = {
   
    async rewrites(){
    return[{
source:"/en",          destination:"/dashboard",
}]}
}

module.exports = nextConfig

what I want is to show in the browser http://localhost:3000 but the contents should be of http://localhost:3000/en/dashboard
Answered by Ray
how did you disable i18n? rename middleware.ts to _middleware.ts?
View full answer

25 Replies

@Ray try ts const nextConfig = { async rewrites() { return [ { source: "/", destination: "/en/dashboard", }, ]; }, } module.exports = nextConfig
 async rewrites(){
    return[

                {
                    source:"/en",
                    destination:"/dashboard",
                }
            ]
    }
    

its working like this but I can see /en/dashboard in the URL
do you have middleware which doing redirecting?
yes
Ok let me disable i18n and try again
still I can see the URL
without any middleware
Yep
@Naeemgg Yep
try clear browser cache
@Naeemgg Ok let me disable i18n and try again
how did you disable i18n? rename middleware.ts to _middleware.ts?
Answer
middl.ts
@Ray try clear browser cache
roger that
do you have app/page.tsx?
yes
import { redirect } from "next/navigation";

const page = () => {
  // redirect("/dashboard")
  return (
    <div>
      HELLO
    </div>
  )
}

export default page
ok
IT WORKED
now could you please tell me how to do this exact thing with middleware??
with i18n??
I'm using next-auth and i18n which are using middleware
Now its working
had to handle the NextResponse.redirect