301 redirect from www to non-www on basic Remix app

I’m doing some testing running a simple remix app, but I couldn’t find a way to manage the 301 redirect from www to non-www URLs

Basically what I’m trying to do is to send all the traffic from www.example.com to example.com

I don’t know if that is possible using some parameter on fly.toml.

On a Digital Ocean machine, I get this done using nginx on the server I’ve created, but IDK how to do it here.

Hi,

You’d do this on Fly.io much the same way as on any other VM provider! The Fly proxy can redirect http requests to https, but it won’t do host rewrites the way you want. So it’s up to what you deploy in your VM to handle that.

You can create a Docker image that has nginx serving and proxying your Remix application; it’s a valid approach.

Your application can also do this directly, internally. You’d need to examine the request’s Host header and if it’s www.example.com, then you respond with a 301 redirect to example.com.

This is typically done with middleware in your framework that inspects every incoming request. I’m not familiar with Remix, but from what I was able to investigate, typically Express is used as the underlying web server, so if you look for Express middleware for Remix you should find some patterns you can use to get this working.

Regards,

  • Daniel

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.