[英]Redirect based on URL/Query Parameters
我基本上只是想根據 URL (或查詢)參數將用戶重定向到不同的站點,但我不知道如何。
If the URL is https://www.tamoghnak.tk/redirect?link=https://www.tamoghnak.tk/gobob
then it should redirect to https://www.tamoghnak.tk /gobob.
If the URL is https://www.tamoghnak.tk/redirect?link=https://stackoverflow.com
then it should redirect to https://stackoverflow.com and so on (Redirect to any site in parameters).
我該怎么做? (在Node、JS、HTML等)
如果你使用 Express,它可能是這樣的:
const app = require('express')();
app.get('/from', (req, res) => {
// The optional first parameter to `res.redirect()` is a numeric
// HTTP status.
res.redirect(301, '/to');
});
app.get('/to', (req, res) => res.send('Hello, World!'));
const server = await app.listen(3000);
const res = await axios.get('http://localhost:3000/from'); // "Hello, World!" res.data;
鏈接https://masteringjs.io/tutorials/express/redirect
您所要做的就是從 get 請求中獲取參數並將其值粘貼到重定向中。
我的代碼:
const app = require('express')();
app.get('/from', (req, res) => {
res.redirect(301, req.query.link);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.