Redirect www to non-www

Hi guys

How can we redirect from https://www.example.com to https://example.com

Thanks

Hey @petrvecera,
I believe that the below example should work for you:

EdgeJS (routes.js):

import { Router, edgioRoutes } from '@edgio/core'

export default new Router()
  .match({
      headers: {
          // Regex or just string 'www.example.com'
          'host': /^www.example.com$/,
      }
  }, ( { setResponseHeader, setResponseCode } ) => {
      // %{normalized_uri} => /path/to/resource?query=string
      setResponseHeader('location', "https://example.com%{normalized_uri}")
      setResponseCode(301)
  })

UI:

Best regards
Jan

1 Like