【发布时间】: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
任何人都可以帮助我,我想从 http://www.example.in/search?city='xyz' 重写 url 到 http://www.example.in/city/xyz 在sails.js中
【问题讨论】:
标签: sails.js
查看文档的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=xyz 和 http://www.example.in/city/xyz 将得到相同的结果,就像您在 Nginx 或 Apache 中使用 url 重写一样。
【讨论】: