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

379
Views
How to add a filename extension to an Next.js url?

Example : I need to redirect this URL : https://example.com/data/publications to this one : https://example.com/data/publications.json

I already tried Next.js redirection but I failed to add a string that is not starting with /

Example, this doesn't work :

  async redirects() {
    return [
      {
        source: '/data/:slug',
        destination: '/data/:slug.json',
        permanent: true,
      },
    ]
  },

Adding () around .json doesn't help

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

0

How about using a middleware? Middleware is a function that executes when client connects to a specific route.

To use middleware; inside your "pages/data" folder, create "_middleware.js" file and use the code below. This code checks if the url has "json" extension end of it. If it doesn't, then it redirects the client to the url with "json" version.

import { NextResponse } from 'next/server';

export default function myMiddleware(req, e) {
  if (!req.url.endsWith("json")) return new NextResponse.redirect(`${req.url}.json`);
}
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!