Netlify rewrite doesn't work

I’m trying to get rewrites to work, I’ve specified two entries, one redirect and the other a rewrite. The redirect works and the rewrite doesn’t;

/test/media/* /api/media/:splat 200
/test2/media/* /api/media/:splat 301

What’s the issue with the rewrite?

I’ve got it working by specifying an absolute url. Is there a generic hostname that can be used so that the rewrite doesn’t have to know in advance what domain it’s being deployed to?

Hi @thor1 :wave:t6: , glad you got the url working. I’m not aware of specific domain deployments in a rewrite. Perhaps you can find something of use in this article?

I assume it doesn’t work with a relative url, due to the target url being a nuxt /api/* url, this is implemented as a netlify function. Does relative rewrites not work with netlify functions?

@thor1 If by “relative rewrites” you mean things like…

/folder/file1  /folder/file2  301!

It definitely works.

You shouldn’t need to specify the domain provided that both the “from” and “to” of the redirect are on the same site.

What kind of value are you trying to pass in via the * to the :splat, is it just something like…


or is it a full URL, (something I’ve seen others try to do), like…

We’re trying to server urls’ that were used in an older website which was migrated to the net setup on netlify. It served at paths such as https://hostname/~/media/some/media/path.jpg

/~/media/* /api/media/:splat 200

I can write a handler that takes anything eg at /~/* and rewrites or redirects to a nuxt api endpoint such as /api/media/some/media/path.jpg and then i do an internal lookup against a mapping to find the new url. It works with 301, but not with 200. That’s why I though that maybe rewrites doesn’t work with netlify functions

With this rule:

/~/media/* /api/media/:splat 200

If you accessed it via:


It would try to return whatever is at:


Is there actually a file in that location? or is that entire path itself a proxy to a function?

If you have an advanced use case, you may be able to achieve it with Edge Functions.

There’s no file at that location no, the /api/* endpoints with nuxt are implemented as serverside endpoints, and netlify has special support for nuxt serverside endpoint implementing them as functions.

That’ll explain why I’ve been a bit confused, as I don’t use nuxt myself and I thought that you were asking a more general question about Netlify redirects.

From what little I do know, I believe you’re correct and that there is middleware that generates serverless functions on your behalf. It’s likely it’s also capable of creating redirects/rewrites.

I don’t know how anything that’s automatically generated interacts with everything else, but the Netlify support team should be able to provide more insight.