Azure static web app - set a status code for a catchall route

Havenless 20 Reputation points
2025-04-06T15:30:10.8333333+00:00

I'm investigating using an Azure static web app as a holding site when the real site is down. The holding site will have limited content and most URLs will return the same explanatory page (at /index.html) with a 503 (service temporarily unavailable) HTTP status.

In the routes list of staticwebapp.config.json, I tried setting the statusCode for a catchall route for /* with a rewrite to /, but this results in the error:

"Encountered an issue while validating staticwebapp.config.json: Status code cannot be specified for a rule with Rewrite specified."

With the statusCode removed, requests with URLs for any page other than the default result in the status code 200, even though I'm setting status code 503 for route /

Is there a way to achieve what I want?

Thanks

Steven

Setting status code with a rewrite isn't allowed (why not?)

        {            
			"route": "/",            
			"statusCode": 503        
		},
        {
            "route": "/*",
			"rewrite": "/",
            "statusCode": 503
        }

This results in status code 200 for requests to anything but the default page

        {
            "route": "/",
            "statusCode": 503
        },
        {
            "route": "/*",
            "rewrite": "/"
        }
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,173 questions
{count} votes

Accepted answer
  1. Siva Nair 2,340 Reputation points Microsoft External Staff Moderator
    2025-04-08T05:44:45.56+00:00

    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

    1. Use redirect instead of rewrite with statusCode: 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:

    1. 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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.