Hi Havenless,
As you are looking to Serve /index.html
for all routes, but with an HTTP 503 status, to indicate "temporarily unavailable."
Azure Static Web Apps doesn't currently support setting a custom HTTP status code (like 503) when using the rewrite
action in staticwebapp.config.json
. This is a known limitation, and as the error message suggests: "Status code cannot be specified for a rule with Rewrite specified."
This means you're stuck with a 200 response if you're rewriting to a common page like /index.html
- Use
redirect
instead ofrewrite
withstatusCode: 503
The config does allow redirect
with a custom statusCode
. So you could do this:
{
"routes": [
{
"route": "/*",
"redirect": "/index.html",
"statusCode": 302
}
]
}
However, this will change the URL in the browser to /index.html
, opt this If URL change is acceptable:
- Use an Azure Front Door or Azure Application Gateway in front of Static Web App
This is the most robust and "correct" way:
- Put your static site behind Azure Front Door.
- In Front Door, configure a routing rule that:
- Detects the app is in "maintenance mode" (via path or header).
- Serves the holding page (from the static site).
- Returns a custom 503 response regardless of the static site status code.
This lets you:
- Show consistent content (
/index.html
).- Retain the requested URL.
- Set the proper HTTP status.
If you have any further assistant, do let me know.If the answer is helpful, kindly upvote and please click Accept Answer it so that other people who faces similar issue may get benefitted from it.