0

In hapijs I need to remove a querystring from a URL if it appears using a prehandler.

For example this URL: https://www.example.com/products/speakers/psb-ps1-232344/?prodSource=speaker%20line%20products

Should redirect to this: https://www.example.com/products/speakers/psb-ps1-232344/

Where I have /products/{brand}/{productName}-{productId}/

1 Answers1

0

You can achieve this by doing a simple split and destructure.

const [url] = "https://www.example.com/products/speakers/psb-ps1-232344/?prodSource=speaker%20line%20products".split("?")
console.log(url)
ITfromPH
  • 86
  • 1
  • 4
  • I actually did it like this: `if (request.path && request.query.prodSource) { var targetUrl = request.path; return reply.redirect(targetUrl).permanent(true); }` – BigBean May 07 '20 at 17:06