When using now.json
's route to perform server side redirects, like the following 3 different cases:
{ "src": "/thoughts/", "dest": "/blogIndex" },
{ "src": "/thoughts", "status": 301, "headers": { "Location": "/thoughts/" } },
{
"src": "/(?<page>[^/]*)/",
"dest": "/?page=$page"
},
{
"src": "/(?<page>[^/]*)",
"status": 301,
"headers": { "Location": "/$page/" }
}
{
"src": "/(?<locale>[^/]*)",
"status": 301,
"headers": { "Location": "https://ibcol-dev.bbi.now.sh/en-gb/how/" }
}
If the original req url path clashes with the name of an existing lambda function entrypoint, instead of a redirect, a black redirect error page will be shown
This is due to a missing Location: <new-location>
in the server response.
When requesting /home
and there is a lambda function called home
; Location is missing from the 301 call.
Trying to request for /contactttt
, there is no lambda function called contactttt
. Location: /contactttt/
is returned along with the 301 status code.
> GET /contactttt HTTP/1.1
> Host: ibcol-dev.bbi.now.sh
> User-Agent: insomnia/6.3.2
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 09 May 2019 12:22:32 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: /contactttt/
< x-now-trace: hkg1
< server: now
< x-now-id: cc5zz-1557404552231-c1a8dc9ffe4c02d2944c8a0f152f591e
< strict-transport-security: max-age=63072000
< cache-control: s-maxage=0
< Strict-Transport-Security: max-age=31536000; includeSubDomains;
> GET /contact HTTP/1.1
> Host: ibcol-dev.bbi.now.sh
> User-Agent: insomnia/6.3.2
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 09 May 2019 12:18:01 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
< x-now-trace: hkg1
< server: now
< x-now-id: cc5zz-1557404281424-5b206880e8e96b5e3e268db9fa7df095
< strict-transport-security: max-age=63072000
< cache-control: s-maxage=0
< Strict-Transport-Security: max-age=31536000; includeSubDomains;
- Renaming the lambda function
- Move the lambda functions inside a subfolder, for NextJS, this can be done by adding a sub folder to /pages/.