solidusjs / solidus

A simple server that generates pages from JSON and Templates
MIT License
28 stars 7 forks source link

Redirect protocol and host #150

Closed joanniclaborde closed 6 years ago

joanniclaborde commented 6 years ago

Adds ability to redirect from and to a specific protocol and/or host. It is now possible to use objects for the from and to properties in redirects.js.

If a from object is used (instead of the usual string or regular expression), the following properties are available:

If a to object is used (instead of the usual string or function), the following properties are available:

Example to automatically redirect to HTTPS and from the root domain to the www subdomain:

// redirects.js
exports = [
  // http://site.com => https://www.site.com, will preserve the url
  {
    from: {
      protocol: 'http',
      host: 'site.com'
    },
    to: {
      protocol: 'https',
      host: 'www.site.com'
    }
  },
  // http://www.site.com => https://www.site.com, will preserve the url
  {
    from: {
      protocol: 'http',
      host: 'www.site.com'
    },
    to: {
      protocol: 'https'
    }
  }  
];