Ask coding questions

← Back to all posts
Node.js - Redirect based on URL/Query Parameters
Retrospicer (10)

I basically just want to redirect the user to a different site based on the url (or query)parameters but I have no idea how.

If the url is then it should redirect to

If the url is then it should redirect to and so on (Redirect to any site in parameters).

How would I do this? (In Node, JS, HTML, e.t.c.)

Thanks in advance!

Answered by Coder100 (18109) [earned 5 cycles]
View Answer
Coder100 (18109)

sure, its easy in js

app.get("/redirect", (req, res) => {

but this only assumes that the user actually created a ?link query.

Retrospicer (10)

@Coder100 Thanks! Before redirects were /redirect/
but now they are /redirect?link=https:/

Coder100 (18109)

but both are invalid??
no link can have //? @TamoghnaK13

Retrospicer (10)

@Coder100 Can you help me here if possible (How-to-only-display-output-in-a-bash-repl) Thanks! @Coder100