Redirects

LaunchFast handles redirects in Express middleware (in server/index.ts) before requests reach Remix. This is more performant than handling them in route loaders and ensures every request is normalized early.

HTTP to HTTPS

All traffic is automatically redirected to HTTPS. This uses Fly's X-Forwarded-Proto header to detect HTTP requests, so it does not affect localhost during development.

app.use((req, res, next) => {
  const proto = req.get('X-Forwarded-Proto')
  const host = getHost(req)
  if (proto === 'http') {
    res.set('X-Forwarded-Proto', 'https')
    res.redirect(`https://${host}${req.originalUrl}`)
    return
  }
  next()
})

Trailing slash removal

URLs ending with / are redirected (301) to their canonical form without the trailing slash. This prevents search engines from treating /about/ and /about as separate pages with duplicate content.

app.use((req, res, next) => {
  if (req.path.endsWith('/') && req.path.length > 1) {
    const query = req.url.slice(req.path.length)
    const safepath = req.path.slice(0, -1).replace(/\/+/g, '/')
    res.redirect(301, safepath + query)
  } else {
    next()
  }
})

www subdomain redirects

DNS-level redirects do not work with Fly, so subdomain redirects must be handled in application code. To set this up:

  1. Register SSL certificates for both the www and root domain in your Fly dashboard under Certificates
  2. Add redirect middleware in server/index.ts

To redirect non-www to www:

app.use((req, res, next) => {
  const host = getHost(req)
  if (!host.startsWith('www.')) {
    return res.redirect(301, `https://www.${host}${req.url}`)
  }
  next()
})

To redirect www to non-www:

app.use((req, res, next) => {
  const host = getHost(req)
  if (host.startsWith('www.')) {
    return res.redirect(301, `https://${host.slice(4)}${req.url}`)
  }
  next()
})