How to return 404 error with Azure static websites?

Jameson Hill 20 Reputation points

I have a static website backed by azure blob storage. When you make a request for a document at a path that doesn't exist in blob storage, azure returns a 404 with the index.html file at the root of the container. This is correct for most cases, but I want to return an error for certain url paths. I found some documentation for a different service, Azure Static Web Apps, where you can exclude certain route paths from returning the index.html file when a 404 occurs. Is this functionality configurable for static websites as well? I've perused the az cli documentation, the azure portal, and various articles but haven't found an answer.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,742 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,479 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
779 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ramya Harinarthini_MSFT 5,306 Reputation points Microsoft Employee

    Jameson Hill

    Welcome to Microsoft Q&A, thank you for posting your here!!

    The static website in Azure Storage GPv2 is different from Azure App Service. It only hosts these static web files which include HTML/CSS/JavaScript files, other files can be handled in browser like images, robots.txt, etc. It has inability to process server-side scripts, due to there is not IIS. So, your web.config file is no sense for it to change the access routing and be belong to server-side script for IIS.

    Actually, you can see the words in Azure portal.

    Configuring the blob service for static website hosting enables you to host static content in your storage account. Webpages may include static content and client-side scripts. Server-side scripting is not supported in Azure Storage. Learn more

    And refer to the Learn more link of Static website hosting in Azure Storage

    In contrast to static website hosting, dynamic sites that depend on server-side code are best hosted using Azure App Service.

    We recommended using Azure App Service for your app if requires the URL-rewrite feature.

    Hope this helps!
    Kindly let us know if the above helps or you need further assistance on this issue.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

1 additional answer

Sort by: Most helpful
  1. Dillon Silzer 54,746 Reputation points

    Hello Jameson,

    Check out the following:

    Create file staticwebapp.config.json in the root of your website.

    Enter this json:

      "responseOverrides": {
        "404": {
          "rewrite": "/404.html",
          "statusCode": 404

    Create 404.html with your custom error.

    Cited from

    If this is helpful please accept answer.