【问题标题】:SEO Redirect with Node.js Sails使用 Node.js Sails 进行 SEO 重定向
【发布时间】:2014-05-20 14:10:20
【问题描述】:

我正在使用 Angular 和 Node.js,并且我有一个重定向机器人来加载 SEO 内容的页面。在快递我有这样的事情:

req.isBrowser = function () {
  var pattern = /(opera|aol|msie|firefox|chrome|konqueror|safari|netscape|navigator|mosaic|lynx|amaya|omniweb|avant|camino|flock|seamonkey|mozilla|gecko)+/i;
  return pattern.test(req.headers['user-agent']);
};

我会在 GET 请求中使用它来进行必要的重定向。虽然很难弄清楚如何在 Sails 中很好地做到这一点。是否有一个地方可以运行此检查,如果它是浏览器,则自动重定向到公用文件夹中的静态文件,否​​则如果它是机器人,则通过 jam/ejs 运行它。

【问题讨论】:

    标签: node.js angularjs express sails.js


    【解决方案1】:

    如果您阅读有关sails 的文档policies,它会讨论如何对sails 进行身份验证。意味着他们可以在每次路由被命中时运行一个函数。

    /config
      - policies.js
    
    // policies.js
    module.exports.policies = {
      "*": "isBrowser"
          // or some controller
      ViewController: {
        "index": "isBrowser"
      },
    }
    
    
    /api
      /policies
        - create a file name "isBrowser.js"
    
    // sBrowser.js
    module.exports = function(req, res, next) {
    
      if (/your logic/) {
        // go back to your normal route function.
        return next();
      } else {
        // do something about SEO bot.
      }
    
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 2016-01-12
      相关资源
      最近更新 更多