Appengine: Routing with dispatch.yaml

2019-09-09 09:35发布

I have a module on Appengine say exmplemodule

And my dispatch.yaml is

application: sampleappname

dispatch:
- url: "*/"
  module: default

- url: "example.abc.com/*"
  module: examplemodule

It is working fine, so when I try to access example.abc.com/index.php it loads the index.php file normally. But what I want is that when i should access example.abc.com the index.php file should open.

How can i achieve this?

Ask me if this much of information is not sufficient to answer this question of mine.

2条回答
迷人小祖宗
2楼-- · 2019-09-09 10:23

Note: my answer comes from the python GAE, I suspect it may be applicable to php as well, but I'm not 100% certain.

I'm using a similar dispatch.yaml, but with just the 2nd rule.

I just tested on my app that a request like example.abc.com is sent to examplemodule and can be seen in the GAE logs for that module (it also started an instance for the module):

enter image description here

From this log it appears to me that example.abc.com is actually expanded to 'example.abc.com/', which means it would be caught by your 1st rule.

First check your logs for both modules to see which one actually gets the request.

If indeed it goes to default I see a few things to try:

  • adding a rule specifically for example.abc.com/ before the one for */
  • reversing the order of your 2 existing rules or even dropping the 1st rule completely (unless you really want to catch directory-only URLs from example.abc.com in default) - I'd leave such rules for each module config separately, not the dispatcher file.

Note: I also have the examplemodule's default handler treat an empty path request in the same manner as a request to the module's homepage to prevent a 404 (likely you need something different for php):

requested_path = self.request.path_info[1:]
if not requested_path:
    requested_path = 'home.html'
查看更多
甜甜的少女心
3楼-- · 2019-09-09 10:23

The yaml file for module examplemodule needs to define a handler for / that routes to index.php

Something like the following

handlers:
# Serve index.php for GET /
- url: /
  script: index.php
查看更多
登录 后发表回答