Alex.Barylski Alex.Barylski - 1 year ago 82
PHP Question

GAE sub-domain within app.yaml

Is it possible to configure app.yaml to use two distinct PHP scripts, with one handling the naked domain and another handling all other sub-domains?

runtime: php55
api_version: 1

- url: /.*
script: naked.php
- url: /.*
script: sub-domains.php

I am reading up on modules right now - is this what will solve my problem?

EDIT | This link leads me to believe I can achieve what I am after by using services and a custom dispatch configuration?

Answer Source

Not possible using the app.yaml pattern routing since the patterns are applied only on the file path portion of the requested URL (without the domain name).

Yes, modules can be mapped to different domains, with routing based on the dispatch.yaml file, which would look somehow along these lines:

  - url: "*"
    module: naked_domain_module

  - url: "**"
    module: subdomain_module


  • the order of rules in the dispatch.yaml matters - first match wins
  • requests with no matches are sent to the default module (you may need to shuffle the rule order/content, depending if you want to make one of the modules the default one)
  • you can't test this routing on the devserver (which doesn't support hostname routing) unless you also have a more specific pattern in the request path - maybe for local testing only? - for which you can add a dispatch rule,

like this:

- url: "*/naked/*"
  module: naked_domain_module

But in this case you need to account for that added path pattern in the naked_domain_module's app.yaml routing as well and revert it when deploying in production. If you keep this path pattern in production then you don't need all this module story as you can latch on it in the app.yaml directly.