Redirect 301 giving GoogleBot 504 errors

I’m performing a 301 redirect of some of the URLs on my Meteor App, the redirect works fine when i check in the browser, but google is seeing them as 504 server errors !!!? Robots.txt is not the issue.

On the server i am doing something similar to the following (I have simplified it for the example here- as the actual case involved a database lookup based on the request)

WebApp.connectHandlers.use(function (req, res, next) {
res.writeHead(301, {
Location: ‘https://samedomain.com/differentURI
});
res.end();
});

Is there any possibility that the db request is asynchronous and had not actually completed?

So as far as I know - querying a collection without using a callback is not async. I amended my demo below to show more context.

WebApp.connectHandlers.use(function (req, res, next) {
     let newUrl = Pages.findOne({ old: req.originalUrl},{fields:{newUrl:1}}).newUrl;
     if (newUrl != undefined){
         res.writeHead(301, {         
                Location: ‘https://samedomain.com/’ + newUrl
         });
         res.end();
     }
     
});

Correct. I just wanted to make sure :slight_smile:

You might try rewriting if (newUrl != undefined){ as if (newUrl){, since undefined can actually be redefined and no longer be undefined! Alternatively use, if (typeof newUrl !== 'undefined'){.

However, in all honesty, that’s clutching at straws.