Redirect shadowing not working as expected

Hi,

I’m trying to see if it’s possible to have a site with a few paths served by Netlify (with Gatsby) and the rest in an existing WordPress site as we slowly migrate more paths over to the Gatsby site.

I found a question on StackOverflow answered by @fool. I’m attempting that answer in my app but can’t get it working correctly. I’m aware that some changes to Redirects and specifically to shadowing, which I’m attempting to use here, are going in effect tomorrow. I’m not sure what the current state of these changes is and if newly setup redirects are already impacted by those changes. I have tried to run my setup on Netlify Dev (v2.40) and am currently deploying on Netlify to see what happens there.

The Gatsby site builds pages for two paths: /shop/:slug and /product/:slug. Any other route should be proxied to a different site. According to the documentation on Shadowing, adding a global redirect should go in effect for any route that doesn’t exist on the filesystem.

/* https://wpsite.com/:splat 200

The site’s file system looks like this:

/shop
  /category-2
    index.html
  /category-2
    index.html
/product
  /product-1
    index.html
  /product-2
    index.html

With the above configuration I would expect the following

https://netlifysite.com/ > https://wpsite.com
https://netlifysite.com/somepage > WPSite – Pre-made WordPress Websites
https://netlifysite.com/shop/category-2 > serve from filesystem
https://netlifysite.com/product/product-1 > serve from filesystem

Currently the redirect rule proxies all traffic to WPSite – Pre-made WordPress Websites.

Curious if anyone has any idea what might be wrong here :slight_smile:

Thanks! Sander

Out of curiosity, do you have the same behavior when trying to fetch index.html directly instead of the directory?

Yep, goes straight to the WP site.

When deploying on Netlify I get the expected results, hooray! However, Netlify Dev doesn’t correctly register the redirects, which makes it very painful to test. Any ideas what might be causing this? I’ll create an issue in the Github repo.

Looks like a fix has already been made, but the latest version (2.41) hasn’t been published on npm yet: Fix rewrite force behavior for static files by RaeesBhatti · Pull Request #776 · netlify/cli · GitHub

Has this truly been fixed?

I am using version 2.46 and still see similar behavior.
The shadowing doesn’t seem to work at all with “netlify dev”

It works correctly in Netlify itself but indeed it hasn’t been fixed in Netlify Dev. I left a comment at that PR I linked to, but I haven’t had time to file a bug report. I’ve downgraded to 2.38.0 and am not using redirects in development for this reason. Might be worth opening an issue on the github repo.

hey @sanderfish and @moop-moop - the best way to get the attention of the folks who work on dev is to file an issue in the CLI repo:

Thanks @sanderfish and @perry
I wasn’t clear about the state of the original problem.
I will troubleshoot to find some simple cases and file a bug report.

We are planning on using Next.js with SSG export for level 1 delivery backed up by serverless for level 2. I suspect it would work on Netlify itself, but I wanted to make sure netlify dev worked too.

1 Like
1 Like

netlify-cli@2.51.0 has just been released which contains improved file shadowing on both request and target URL’s. Please try it out and let us know!