Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure custom 404 page

I have created a web application using Microsoft Azure and uploaded static html pages to the web application.

It works fine, however, I would like to set a custom 404 page. Where or how can I do this using the Azure portal ?

Just to be clear, this is not a visual studio project, it's just some static html files. I just want to tell azure to use my 404 page instead of the default text it displays when a page cannot be found.

EDIT

Please note, this has nothing to do with IIS. I dont even have a web.config file. I am simply hosting some static html files in Azure and want a custom 404 page. I have already made the 404.html page.

like image 593
Janpan Avatar asked Jul 12 '16 17:07

Janpan


2 Answers

Seems like you have to add a web.config file in your root directory. This seems like a workaround, but doing that and adding the following code works:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="/404.asp" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>
like image 198
Janpan Avatar answered Oct 21 '22 05:10

Janpan


Follow these steps to configure a custom 404 page for a Azure Static Web App:

  • Create a file named staticwebapp.config.json in root page (same folder as starting page i.e. index.html)

  • put these lines inside it:

     {       
        "responseOverrides": {
          "404": {
            "rewrite": "/404.html"
          }
        }
     }
    
  • Put your custom 404 page in root or subfolder (in this example 404.html is in root folder)

like image 26
ozanmut Avatar answered Oct 21 '22 05:10

ozanmut