301 redirects using Express.js / Node.js

 301 Redirect with Node.js / Express.js - Tutorial with Example (stackfame.com)

const express = require('express');
const app = express();
const port = 3000;
app.get('/old-url/', (req, res, next) => {
res.redirect(301, 'https://new-doamin.com/new-url');
});
app.listen(port, () => {
console.log('Server is running at port: ',port);
});
sadasdasd

and if you want force live request using express middleware use following code:

// forced 301 redirect using express middleware
const express = require('express');
const app = express();
const port = 3000;
app.use((req, res, next) => {
var host = req.get('Host');
if (host === 'www.old-domain.com') {
return res.redirect(301, 'https://new-domain.com/' + req.originalUrl);
}
return next();
});
app.listen(port, () => {
console.log('Server is running at port: ',port);
});

Không có nhận xét nào:

Is it okay to use both fetchpriority="high" and loading="eager" in img tag?

 https://stackoverflow.com/questions/77744344/is-it-okay-to-use-both-fetchpriority-high-and-loading-eager-in-img-tag Yes Fetchpriority and l...