Rewrite is not working as expected on free plan

Hello,

I’m trying to use rewrites but they are not working properly on my netlify free account.

/blog/sample-post is redirected to /sample-post with a 301 redirect.

Site: https://fanciful-phoenix-62212b.netlify.app
Blog: https://fanciful-phoenix-62212b.netlify.app/blog

Rewrites:

[[redirects]]
  from = "/blog/*"
  to = "https://netlifyfreeaccount.superblog.cloud/:splat"
  status = 200

[[redirects]]
  from = "/_elderjs/*"
  to = "https://netlifyfreeaccount.superblog.cloud/_elderjs/:splat"
  status = 200

p.s.:
A similar setup is working on my paid netlify account perfectly

Hi, @s-kris. I’m getting identical content for those two URLs:

$ curl -s https://netlifyfreeaccount.superblog.cloud/ | md5sum
4ad05f68579b318dc70ad681e16e8e97  -
$ curl -s  https://fanciful-phoenix-62212b.netlify.app/blog/ | md5sum
4ad05f68579b318dc70ad681e16e8e97  -

Based on this the redirect is working. Were you expecting some other behavior or did you already resolve the issue?

Hey Luke

The issue is not resolved. The one you saw works fine. Nested routes are causing the issue (I mentioned the sample URL in the post).

https://fanciful-phoenix-62212b.netlify.app/blog/sample-post it is redirected to https://fanciful-phoenix-62212b.netlify.app/sample-post

i.e. /blog is removed.

Screenshot 2022-04-14 at 12.43.08 PM

Here is an attached curl md5
Screenshot 2022-04-14 at 12.47.51 PM

This doesn't happen with another site which is on my PRO netlify account

Hey @s-kris

Given navigating to https://fanciful-phoenix-62212b.netlify.app/sample-post directly returns a 404, I believe you are missing the SPA rewrite required by React.

https://fanciful-phoenix-62212b.netlify.app/blog/sample-post is redirected to https://fanciful-phoenix-62212b.netlify.app/sample-post by netlify. (please see the network logs in the screenshots attached)

Why is that happening?

Can you share the repository you are deploying from? This may help isolate the issue.

Sure!

As per my previous post, React apps (and other SPAs) require a rewrite in the form

/*   /index.html   200

for _redirects or for netlify.toml (which you would use given you already have such a file)

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

otherwise app routing (e.g. with react-router) will not work. You don’t have this so the default Netlify 404 is displayed.

Naturally, this affects all paths, so you would need to ensure this is the last rule (i.e. below the two you currently have)

The (Svelte?) app at https://netlifyfreeaccount.superblog.cloud/ uses absolute URLs e.g. https://fanciful-phoenix-62212b.netlify.app/blog/sample-post. This means you have no way of testing the site standalone to ensure it works.

As you are trying to proxy to an SPA from a site running another SPA, I am not sure there is an easy way to accomplish what it appears you are setting out do to. I might suggest setting the base path for the blog to /blog *(i.e. https://netlifyfreeaccount.superblog.cloud/blog/) so that is operates on the same path you wish to access it on via the main site rewrite.

As far as I am aware, there is no difference in the behaviour of redirects on any of the Netlify tiers, so I don’t believe this has anything to do with the use of the free tier.

  1. I’m aware of the catch-all route (/*) for SPAs but I didn’t want to include that rule in the sample repo to show the 404.

  2. Yes, it is a svelte app and it is hosted on netlify as well.

  3. I got it working by disabling pretty URLs on the svelte app.

  4. But I can say that the same is working on my PRO account as intended without disabling pretty urls. Interestingly my client upgraded their free account to PRO plan but the same dint replicate.

  5. Happy to get on a google meet call to show what I’m saying. I hope I’m not crazy :smiley:

It’s not just about showing (or not) a 404. It means direct links to the app will NOT work.

Again, I don’t believe this is anything to do with account level.

I don’t use Google meet.

Not sure what you are referring to. I got the problem fixed and you can test the URL now: https://fanciful-phoenix-62212b.netlify.app/blog/sample-post. Regarding catch-all route, I’m pretty sure how it works for SPAs and netlify rewrites.

In this instance, I did NOT use the catch-all route but got my use-case working (you can see the repo code).

No worries, I just wanted to show you guys what I’ve been telling you for quite some time. Thanks for your time

1 Like

Great you managed to get it working @s-kris

1 Like

Hi, @s-kris. If you are getting a 301 for a proxied URL, then the 301 is coming from the proxy target. If you don’t want a 301 returned then the proxy target would need to be reconfigured.

Hey B Luke

I did configure the proxied url.
But my account and others behaved differently as mentioned in the post.

Hi, @s-kris. If you tell us the URL we can check it to research what is happening and what the cause is.

You can post that information publicly or you can private message (PM) that to one of our support staff. I’ve confirmed that PMs are enabled for your forum login. Please keep in mind that only one person can see the PM and this will likely mean a slower reply than posting the information publicly. Please feel free to reply to however you prefer though.