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-09-03。"],[[["\u003cp\u003eThe \u003ccode\u003edispatch.yaml\u003c/code\u003e file allows you to define routing rules to direct incoming requests to specific services based on the URL's path or hostname.\u003c/p\u003e\n"],["\u003cp\u003eEach rule in \u003ccode\u003edispatch.yaml\u003c/code\u003e specifies a URL pattern and the service that should handle requests matching that pattern, with rules being order-dependent and only the first matching rule applied.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eREGION_ID\u003c/code\u003e, an abbreviation assigned by Google, is included in App Engine URLs for apps created after February 2020, and it is optional for apps created before this date.\u003c/p\u003e\n"],["\u003cp\u003eYou can use glob patterns like \u003ccode\u003e*\u003c/code\u003e in the \u003ccode\u003eurl\u003c/code\u003e element, but only before the hostname and at the end of the URL path, to define broader routing rules in the \u003ccode\u003edispatch.yaml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eDeploying the updated \u003ccode\u003edispatch.yaml\u003c/code\u003e file with \u003ccode\u003egcloud app deploy dispatch.yaml\u003c/code\u003e updates the routing rules, and you can remove all rules by setting \u003ccode\u003edispatch: []\u003c/code\u003e and redeploying.\u003c/p\u003e\n"]]],[],null,["# dispatch.yaml Configuration File\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\nGo Java Node.js PHP Python Ruby \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/standard/python/how-requests-are-routed#region-id). \nOK\n\nThe `dispatch.yaml` allows you to override [routing\nrules](/appengine/docs/standard/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/standard/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\nThe routing rules also apply to URLs that are used in a [cron file](/appengine/docs/standard/scheduling-jobs-with-cron-yaml).\n\n\n\u003cbr /\u003e\n\nDeploying the dispatch file\n---------------------------\n\n\u003cbr /\u003e\n\n\nBefore you deploy your dispatch file, you must ensure that all the services\ndefined in that file have already been deployed to App Engine. To deploy\nthe `dispatch.yaml` file, run the\n[`gcloud app deploy`](/sdk/gcloud/reference/app/deploy) command from the\ndirectory that contains the `dispatch.yaml`: \n\n gcloud app deploy dispatch.yaml\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nFor more information about the deployment commands, see [Deploying an App](/appengine/docs/standard/testing-and-deploying-your-app#deploying_your_application).\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."]]