Hello everyone!
Okay tl;dr – I’m trying to setup a 301 redirect from http://localhost to http://dev.localhost, but when I tell that to netlify.toml, it seems to instead redirect me to /, which results in a redirect loop. Full story:
In order to get around an issue using magic.link with Brave, I need to access my dev site (which I start with netlify dev) at the domain http://dev.localhost instead of http://localhost. (Brave seems to resolve anything *.localhost to 127.0.0.1, which makes things easier for me, but if it didn’t then I’d just update /etc/hosts)
So nowadays I start up netlify dev, it automatically opens my browser to http://localhost, then I manually change that to http://dev.localhost in the address bar. And that does what I need it to do.
That works just fine, but I’d like to automate it. There doesn’t seem to be a way to tell netlify dev to open the page at a specific site (whereas, for example, snowpack allows the user to config a specific hostname to open … doesn’t help here, just wanted to show an analogous option in a different tool). Okay fine, maybe I can accomplish this with a redirect?
So I put in my netlify.toml file a section that looks like this:
[[redirects]]
force = true
from = "http://localhost"
status = 301
to = "http://dev.localhost"
But when I start the server, I just get an error about too many redirects. Looking in the network tab, I see that it’s redirecting me to / instead of http://dev.localhost. And indeed when I run curl I get
❯ curl http://localhost:8888
Redirecting to /%
I’ve also tried wildcarding the from and splatting the to, with the same results.
Is this normal/expected behavior for redirects? Is there some way I can configure a redirect to do what I want, and if not, is there some other way I can get the browser to automatically show me http://dev.localhost instead of http://localhost when I start up netlfiy dev?