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

132
Views
Query String missing when redirecting with expressjs

I have the following express js route which helps in redirecting to the given URL.

app.get("/", async (req, res) => {
  const url = req.query.url;
  res.redirect(url);
});

It's working fine. But the problem is, somehow the passed query strings is getting cut off for no reason.

Example:

This is what I'm actually passing.

http://localhost:3000/?url=https://google.com/?abc=123&def=456&aaa=098

After redirecting whatever after the first query string goes missing.

It's appearing like this.

https://google.com/?abc=123

Not sure why &def=456&aaa=098 goes missing.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use the encodeURIComponent and decodeURIComponent functions.

For example:

app.get("/", async (req, res) => {
  const url = req.query.url;
  res.redirect(decodeURIComponent(url));
});

Note that the url parameter must be encoded in the actual URL.
Your URL should look something like this:

http://localhost:3000/?url=https://google.com/%3Fabc%3D123%26def%3D456%26aaa%3D098
over 4 years ago · Santiago Trujillo 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!