Docs Menu

사용자 정의 404 페이지 사용

You can replace the default 404 page that Atlas App Services displays when a user tries to access a resource that does not exist with a custom HTML document. You can specify this custom 404 page from the App Services UI or by importing an application configuration directory that includes the page in its hosting directory. Select the tab below that corresponds to the method you want to use.

참고

단일 페이지 앱의 404 오류

When single-page application hosting is enabled, App Services always returns an HTTP 200 response with the app root regardless of the requested route. This means that you cannot specify a custom 404 page for a SPA. Instead, you should include custom code in your application to handle invalid routes.

1

You can use any hosted file as your custom 404 page. It's common to use an HTML file that incorporates the following elements:

  • A short message indicating the error, e.g. "This page does not exist."

  • Alternative links or options for the user to continue navigating.

2

Once you've created the custom 404 file, you need to upload it to App Services. To upload the file, navigate to the Hosting screen of the App Services UI, click Upload Files, and select the custom HTML file.

3

Once you have successfully uploaded the 404 file, all that's left is to configure App Services to serve that file instead of the default 404 page.

  1. On the Hosting page, click the Settings tab.

  2. Under Custom 404 Page, click Choose File.

  3. Select your custom 404 file from the list.

  4. Save를 클릭합니다.

Once you have updated the Hosting configuration, App Services will begin serving your custom file instead of the default 404 page.

1

To configure a custom 404 page with the 앱 서비스 CLI, you need a local copy of your application's configuration files.

최신 버전의 앱의 로컬 사본을 가져오려면 다음을 실행하세요.

appservices pull --remote="<Your App ID>"

Realm UI의 Deploy > Import/Export App 화면에서 애플리케이션의 구성 파일 사본을 다운로드할 수도 있습니다.

2

You can use any valid HTML file for your application's 404 page. Consider incorporating the following elements:

  • A short message indicating the error, e.g. "This page does not exist."

  • Alternative links or options for the user to continue navigating.

3

Once you've created the custom HTML file, you need to host it in App Services.

If you aren't already hosting the HTML file in App Services, add it to the hosting/files/ directory.

4

In hosting/config.json, set default_error_path to the resource path of the 404 page HTML file then save the configuration file.

"hosting": {
"enabled": true,
"default_error_path": "/pages/custom_404.html"
}
5

Once you've updated hosting/config.json you can push the updated config to your remote app. If you also added the 404 page, make sure to use the --include-hosting flag. App Services CLI immediately starts to serve your custom 404 page on push.

appservices push --remote="<Your App ID>" --include-hosting