Redirect issues with Netlify Dev

Hi gang,
I’m having a problem with my redirects locally with Netlify Dev. The gist of what I’m trying to achieve is pretty much summed up in this tweet: and this tweet:

Essentially, fetch images and use cloudinary to optimize my images but if there is a 404 fall back to the local image.
The way I think this should work is:

  • When the site is live (on Netlify) all images will be sent to Cloudinary and be optimized and then proxied through Netlify
  • When being developed locally (on Netlify Dev) the Cloudinary bit will return a 404 and Netlify Dev would fall back to the second redirect to return the local image.

This is what I have in my netlify.toml
command = “npm run production”
publish = “dist”

  framework = "#custom"
  command = "npm run dev"
  publish = "dist"
  targetPort = 8081
  port = 8888

  from = "/img/:image"
  to = ",f_auto,w_auto,dpr_auto/"
  status = 200

  from = "/img/*"
  to = "/images/:splat"
  status = 404

The site is developed in Eleventy, but not in the default folder structure, hence why the [dev] block is custom framework.

What currently happens in Netlify Dev with these redirects is if the image exists on the live server already, it will load with the proxying in place. If the image is not on the live server but is on my dev server (Netlify dev) I get a 404. What I was after with these redirect was:

  • If it’s on live then great load the Cloudinary optimized version proxied through Netlify
  • If not, then no worries just fall back to the local image and proxy

I know I must have missed something or misunderstood something, just hoping someone here can shine a light here for me :slight_smile:


hey @rjdusk ! i am going to try and get some :eyes: on this - maybe even from @philhawksworth . In the meantime, can you let us know which version of Dev you are using?

Thanks @perry any help would be much appreciated :slight_smile: I’m using the latest version of Dev - netlify-cli/3.17.1 darwin-x64 node-v15.8.0 - I forgot to add what the custom framework command (npm run dev) was doing, I’ve added this below for completeness:

ELEVENTY_ENV=development npx @11ty/eleventy --config=.eleventy.config.js --serve --port=8081 & webpack --watch --progress --config=node_modules/laravel-mix/setup/webpack.config.js  

Thanks again for any insights team :slight_smile:

Interestingly enough if I add this redirect to my netlify.toml file

  from = "/bizz/"
  to = "/about/"
  status = 404

it also results in a 404

Cannot GET /bizz/index.htm

So it appears its not exclusive to the images, but to the 404’s in general. Plus some noodling around online I found this issue: Bug: re-write rules are not applied for non static servers · Issue #1242 · netlify/cli · GitHub

i recommend you ask on that issue - that might be the best way to get some assistance with this specific thing, @rjdusk !

1 Like