简体   繁体   中英

Sails.js redirect www to no www url

Is there a way to redirect all incoming requests for something like www. example.com to example.com in Sails (removing www)? In xampp php server this was usually done with .htaccess. How do we go about it in Sails.js (node) server.

Sails.js uses express. Which means any middleware for express will work, such as

Here is the relivant documentation on the sails.js site.

Example using the subdomain module config/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'
    ]
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM