Reputation: 768
First off, this is not about a redirect after a POST request via Ajax as I'm aware there're a lot of SO questions regarding this.
What I want is redirecting all requests from /
to /app
. However, using the following:
/* GET home page. */
router.get('/', function(req, res, next) {
res.redirect('/app');
});
.. it shows the content of the /app
route without changing the URL in browser. It stays the same https://example.com/
.
Is there a way to actually redirect with a 302
or 301
http status code?
Upvotes: 1
Views: 2095
Reputation: 801
res.redirect takes two arguments (code, location). code corresponds to HTTP status code . By default code is taken as 302 which means The requested resource resides temporarily under a different URI.
Use 301 code for permanent redirect
res.redirect(301, '/app')
Upvotes: 2