【问题标题】:How to rewrite URL in sails.js如何在sails.js 中重写URL
【发布时间】:2015-11-25 14:46:59
【问题描述】:

任何人都可以帮助我,我想从 http://www.example.in/search?city='xyz' 重写 url 到 http://www.example.in/city/xyz 在sails.js中

【问题讨论】:

  • 您尝试过哪些方法不起作用?您是否查看过任何 Sails 文档,例如显示重定向 URL 示例的 controllers docs

标签: sails.js


【解决方案1】:

查看文档的url slug 部分。

您可以创建这样的路线:

// config/routes.js
module.exports.routes = {
  // The simple route you use to access to the search controller for now
  'get /search': 'SearchController.index'

  // The "rewritten" route that calls the same controller
  // processing ":city" as if it was part of the query string
  'get /city/:city': 'SearchController.index'
}

然后,http://www.example.in/search?city=xyzhttp://www.example.in/city/xyz 将得到相同的结果,就像您在 Nginx 或 Apache 中使用 url 重写一样。

【讨论】:

    猜你喜欢
    • 2013-11-08
    • 2011-05-18
    • 2021-04-24
    • 2012-09-04
    • 2019-01-24
    • 2015-09-02
    • 2011-04-20
    • 2014-12-07
    • 1970-01-01
    相关资源
    最近更新 更多