Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
Next.js app in subfolder with basePath, how to make home page available outside of basePath?

My Next.js application is running in the '/portal/' folder and basePath is set as follows:

module.exports = {
    basePath: '/portal'
}

Now I need index page of that application to be also available in site root (without basePath). So that both '/' and /portal/*' will be handled by Next.js app while other routes are handled by another web apps. On Nginx side root route is passed to Next.js app, but it isn't clear how to serve a page outside of basePath. I tried rewrites:

async rewrites() {
    return [
        {
            source: '/',
            destination: '/portal/',
            basePath: false
        },
    ];
},

but got an error: The route / rewrites urls outside of the basePath. Please use a destination that starts with `http://` or `https://` https://nextjs.org/docs/messages/invalid-external-rewrite Is it possible to serve one page outside of basePath or the only way is to remove basePath and change all paths and links in Next.js app manually?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Probably using Redirects could be helpful in your case.

module.exports = {
  basePath: '/portal',
  async rewrites() {
  return [
          {
              source: '/',
              destination: '/portal/',
              basePath: false
          },
      ];
  },
  async redirects() {
    return [
      {
        source: '/with-basePath', // automatically becomes /portal/with-basePath
        destination: '/another', // automatically becomes /portal/another
        permanent: false,
      },
      {
        // does not add /docs since basePath: false is set
        source: '/without-basePath',
        destination: '/another',
        basePath: false,
        permanent: false,
      },
    ]
  },
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!