GAE, Cannot find requsted url /index.html on this server

Viewed 55

I have been working on a website that I am using google app engine to host. Everything is working on my localhost. It is a very simple website where the home page is an index.html file with 3 pages. I am using php for form handling. I am sure that the issue is somewhere in my app.yaml file. I am new to GAE and I have tried several examples on the web. When I deploy there are no errors. This is the best file I have come up with:

     runtime: php74

     handlers:
      - url: /index.html
        static_files: /index.html
        upload: /index.html, /campsite-form-results.php, /contact_us.php

      - url: /(.*)
        static_files: /\1
        upload: /(.*)

Whenever I try to browse to the website I get this error:

 Error: Not Found
 The requested URL / was not found on this server.

Please comment if I can add anything that would be helpful. Thank you.

1 Answers

It is not specified if you are using GAE Standard or Flex, but I will refer to the standard version, as the app.yaml configuration file you have provided has the same structure.

What I first noticed is that you are using the static_file as Handler element:

Optional. A static file pattern handler associates a URL pattern with paths to static files uploaded with the application. The URL pattern regular expression can define regular expression groupings to be used in the construction of the file path. You can use this instead of static_dir to map to specific files in a directory structure without mapping the entire directory.

The content of the element you are using is more similar to the static_dir one, that uses MIME types.

Optional. The path to the directory containing the static files, from the application root directory. Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file.

Each file in the static directory is served using the MIME type that corresponds with its filename extension unless overridden by the directory's mime_type setting. All of the files in the given directory are uploaded as static files, and none of them can be run as scripts.

So, now you can choose which of them you want to use, trying to follow the correct declaration of the path.

Talking about the upload element:

Optional. A regular expression that matches the file paths for all files that will be referenced by this handler. This is necessary because the handler cannot determine which files in your application directory correspond with the given url and static_files patterns. Static files are uploaded and handled separately from application files. The example above might use the following upload pattern: archives/(.)/items/(.)

All these elements are optional, as the description says, I will leave the description of the url as well just in case you want to check it.

Required element under handlers. The URL pattern, as a regular expression. The expression can contain groupings that can be referred to in the file path to the script with regular expression back-references. For example, /profile/(.)/(.) would match the URL /profile/edit/manager and use edit and manager as the first and second groupings.

In such case I would recommend:

handlers:
- url: /index
    static_dir: index
    upload: .*\.(html|php)$
    # I'm not a regex expert. This can also work for your specified files:
    # (?=index)\.(html)|(?=campsite-form-results)(?=contact_us)\.(php)$

Please give a read to the app. yaml Reference, also try different Regex with the help of this page in case you do not have experience.

Related