dispatch:# Default service serves the typical web resources and all static resources.-url:"*/favicon.ico"service:default# Default service serves simple hostname request.-url:"simple-sample.uc.r.appspot.com/"service:default# Send all mobile traffic to the mobile frontend.-url:"*/mobile/*"service:mobile-frontend# Send all work to the one static backend.-url:"*/work/*"service:static-backend
如果您更倾向于使用可与大量可能的请求相匹配的宽泛路由规则,则可以定义范围更广泛的规则。
示例:
# Send any path that begins with “simple-sample.uc.r.appspot.com/mobile” to the mobile-frontend service.-url:"simple-sample.uc.r.appspot.com/mobile*"service:mobile-frontend# Send any domain/sub-domain with a path that starts with “work” to the static backend service.-url:"*/work*"service:static-backend
您也可以编写更严格的表达式。
示例:
# Matches the path "/fun", but not "/fun2" or "/fun/other"-url:"*/fun"service:mobile-frontend# Matches the hostname 'customer1.myapp.com', but not '1.customer1.myapp.com.-url:"customer1.myapp.com/*"service:static-backend
# Matches the domain name 'customer1.myapp.com' and directs all the request to default service -url:"customer1.myapp.com/*"service:default# Matches all the subdomains of 'customer1.myapp.com' and directs all the request to static-backend service-url:"*.customer1.myapp.com/*"service:static-backend
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-20。"],[[["\u003cp\u003eThe \u003ccode\u003edispatch.yaml\u003c/code\u003e file allows you to route incoming requests to specific services based on the URL's path or hostname, overriding the default routing rules, and an app can only have one \u003ccode\u003edispatch.yaml\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eREGION_ID\u003c/code\u003e is a code assigned by Google based on the region selected when creating an app and is included in App Engine URLs for apps created after February 2020.\u003c/p\u003e\n"],["\u003cp\u003eDispatch rules in the \u003ccode\u003edispatch.yaml\u003c/code\u003e file are order-dependent, with only the first matching rule being applied to a URL.\u003c/p\u003e\n"],["\u003cp\u003eURL patterns in dispatch rules must use the "\u003ccode\u003e.\u003c/code\u003e" notation for subdomains, and the \u003ccode\u003eurl\u003c/code\u003e element supports glob patterns like the \u003ccode\u003e*\u003c/code\u003e wildcard but only before the host name and at the end of the path.\u003c/p\u003e\n"],["\u003cp\u003eYou can deploy the \u003ccode\u003edispatch.yaml\u003c/code\u003e by using the command \u003ccode\u003egcloud app deploy dispatch.yaml\u003c/code\u003e, and to delete all rules simply edit the file to \u003ccode\u003edispatch: []\u003c/code\u003e and re-deploy.\u003c/p\u003e\n"]]],[],null,["# dispatch.yaml Configuration File\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nGo Java Node.js PHP Python Ruby .NET Custom \n\n### Region ID\n\nThe \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is an abbreviated code that Google assigns\nbased on the region you select when you create your app. The code does not\ncorrespond to a country or province, even though some region IDs may appear\nsimilar to commonly used country and province codes. For apps created after\nFebruary 2020, \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e`.r` is included in\nApp Engine URLs. For existing apps created before this date, the\nregion ID is optional in the URL.\n\nLearn more\n[about region IDs](/appengine/docs/flexible/python/how-requests-are-routed#region-id). \nOK\n\nThe `dispatch.yaml` allows you to override [routing\nrules](/appengine/docs/flexible/how-requests-are-routed#routing_via_url).\nYou can use the `dispatch.yaml` to send incoming requests to a specific service\n(formerly known as modules) based on the path or hostname in the URL.\n\nFor more information, see [How Requests are Routed](/appengine/docs/flexible/how-requests-are-routed).\n\nAn app can have only one `dispatch.yaml` file, and the routing rules in that file\napply to all of the app's services and versions.\n\n\n\u003cbr /\u003e\n\nDeploying the dispatch file\n---------------------------\n\nTo deploy and apply the configuration settings from your dispatch file to your\nApp Engine environment: \n\n gcloud app deploy dispatch.yaml\n\nSyntax\n------\n\nThe root element in the `dispatch.yaml` file is `dispatch:` and contains a list\nof routing definitions that are specified by the following subelements.\n\nThe rules that you define in your dispatch file must use HTTP URL patterns\nthat include the \"`.`\" notation for separating subdomains. URLs\ndefined with the HTTPS \"`-dot-`\" notation are not supported.\n\nDispatch rules are order dependent, and only the first rule that matches a URL\nwill be applied.\n\nExample\n-------\n\nThe following is a sample dispatch file that routes requests to\n`https://simple-sample.uc.r.appspot.com` and requests like\n`https://simple-sample.uc.r.appspot.com/favicon.ico` to the `default` service. All\nstatic content is served from the `default` service. Mobile requests like\n`https://simple-sample.uc.r.appspot.com/mobile/` are routed to a mobile frontend, and\nworker requests like `https://simple-sample.uc.r.appspot.com/work/` are routed to a\nstatic backend.\n\nExample: \n\n dispatch:\n # Default service serves the typical web resources and all static resources.\n - url: \"*/favicon.ico\"\n service: default\n\n # Default service serves simple hostname request.\n - url: \"simple-sample.uc.r.appspot.com/\"\n service: default\n\n # Send all mobile traffic to the mobile frontend.\n - url: \"*/mobile/*\"\n service: mobile-frontend\n\n # Send all work to the one static backend.\n - url: \"*/work/*\"\n service: static-backend\n\nIf you prefer general routing rules that match many possible requests, you can\ndefine rules with wider scopes.\n\nExample: \n\n # Send any path that begins with \"simple-sample.uc.r.appspot.com/mobile\" to the mobile-frontend service.\n - url: \"simple-sample.uc.r.appspot.com/mobile*\"\n service: mobile-frontend\n\n # Send any domain/sub-domain with a path that starts with \"work\" to the static backend service.\n - url: \"*/work*\"\n service: static-backend\n\nYou can also write expressions that are more strict.\n\nExample: \n\n # Matches the path \"/fun\", but not \"/fun2\" or \"/fun/other\"\n - url: \"*/fun\"\n service: mobile-frontend\n\n # Matches the hostname 'customer1.myapp.com', but not '1.customer1.myapp.com.\n - url: \"customer1.myapp.com/*\"\n service: static-backend\n\nYou can create rules to re-direct your incoming domain requests to a service.\nThe following rules route incoming requests from \"customer1.myapp.com\" to the\ndefault service and incoming requests from subdomains to a static backend\nservice.\n\nExample: \n\n # Matches the domain name 'customer1.myapp.com' and directs all the request to default service \n - url: \"customer1.myapp.com/*\"\n service: default\n\n # Matches all the subdomains of 'customer1.myapp.com' and directs all the request to static-backend service\n - url: \"*.customer1.myapp.com/*\"\n service: static-backend\n\nLimits\n------\n\nThe dispatch file can contain up to 20 routing rules. When specifying the URL\nstring, neither the hostname nor the path can be longer than 100 characters.\n\nDeleting all dispatch rules\n---------------------------\n\nTo delete all dispatch rules:\n\n1. Edit the contents of the `dispatch.yaml` file to:\n\n dispatch: []\n\n2. Deploy the `dispatch.yaml` file to App Engine."]]