[英]How to add robots.txt to a node application?
將robots.txt添加到節點應用程序的最佳,最先進和最新的方法是什么?
是否可以在Web服務器級別更好地處理?
PS:我使用Mongo作為數據庫,使用Nginx作為Web服務器。
使用中間件功能。 這樣,您可以為不同的環境(例如生產和開發)處理不同的robots.txt文件。
app.use('/robots.txt', function (req, res, next) {
res.type('text/plain')
res.send("User-agent: *\nDisallow: /");
});
您還可以在文件所屬環境的文件夾中提供文件。
if (app.settings.env === 'production') {
app.use(express['static'](__dirname + '/production')); // Uses the robots.txt from production folder
} else {
app.use(express['static'](__dirname + '/development')); // Uses the robots.txt from development folder
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.