有没有办法将所有传入的请求(例如 www.
example.com)重定向到 Sails 中的 example.com(删除 www)?在 xampp php 服务器中,这通常是通过 .htaccess 完成的。我们如何在 Sails.js(节点)服务器中进行操作。
最佳答案
Sails.js 使用express。这意味着任何 Express 中间件都可以工作,例如
这里是 sails.js 站点上的相关文档。
使用子域模块的示例 配置/http.js
module.exports.http = {
middleware: {
removeSubDomain: require('subdomain')({base: 'yourdomain.com'}),
// Now configure the order/arrangement of our HTTP middleware
order: [
'startRequestTimer',
'removeSubDomain',
'cookieParser',
'session',
'bodyParser',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'router',
'www',
'favicon',
'404',
'500'
]
}
}
关于javascript - Sails.js 将 www 重定向到无 www url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28202066/