Hey guys,
I have a few subdomains set up and want to stream my traffic into different project directory based on the subdomain being visited.
A minimal version of my vercel.json looks like this -
{
“rewrites”: [
{
“source”: “/test”,
“destination”: “/test/$1”
},
{
“source”: “/(.*)”,
“has”: [{ “type”: “host”, “value”: “api.example.com ” }],
“destination”: “/api/$1”
}
],
“trailingSlash”: false
}
So the trailingSlash rule and the /test rule are both working as expected.
The rules like the api for the subdomain matching don’t seem to work.
Expected behaviour -
api.example..com/test shall fetch /api/test and show a 404 error.
Actual behaviour -
api.example..com/test happily shows /test
I wonder if the has condition on host actually works or not. I thought I did everything right here. Please help if you have any ideas. Thx.
system
(system)
May 5, 2025, 8:41am
2
There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.
Sometimes things don’t go as expected when deploying a website. If you see a 404 on your site, that means the page or resource couldn’t be found.
There are many possible causes, and the absence of something can be tricky debug if you don’t know where to look. Here are some things you can do to find the cause and fix it.
Debugging Tips
Check the error code
If you see a mostly white screen with 404: NOT_FOUND along with a Code and and ID then you can click the blue info box below the error deta…
A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0 .
swarnava
(Swarnava Sengupta)
May 5, 2025, 9:26am
3
I think in your case, the /test
rule is being processed before your subdomain rule, which is why api.example.com/test
is showing /test
instead of /api/test
. Does this work?
{
"rewrites": [
{
"source": "/(.*)",
"has": [{ "type": "host", "value": "api.example.com" }],
"destination": "/api/$1"
},
{
"source": "/test",
"destination": "/test/$1"
}
],
"trailingSlash": false
}
Sorry I raised a bad example. I was trying to show the rewrite works without the “has”.
In my real setup I only have subdomain routing, and all of them won’t work.
junyaoau
(hastyq)
May 5, 2025, 11:18am
5
It’s just buggy. I think wrong with the nginx setup. Anyway I fallback to using middleware to control and reverted my vercel.json.