在Google App Engine上加载子文件夹时出现错误404 [英] Error 404 when loading subfolder on google app engine

查看:92
本文介绍了在Google App Engine上加载子文件夹时出现错误404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有index.html作为主页的网站,该网站可以正常工作,但是我想创建一个包含子文件夹的网站结构,因此我创建了一个名为"team"的文件夹,在团队内部,我将index.html文件与团队信息.当我加载www.mysite.com/team/index.html时,它工作正常,但是如果加载www.mysite.com/team,我将收到404错误. 我如何解决此问题以自动在子文件夹中加载index.html?

I have a website with an index.html as homepage that works fine, but i want to create a website structure with subfolders, so i create a folder named "team", inside team i put an index.html file with the team information. When i load www.mysite.com/team/index.html it works fine, but if i load www.mysite.com/team i get an 404 error. how i do fix this for automatically load the index.html inside the subfolder??

我正在使用Google App Engine作为服务器,我使用Google App Engine启动器上传文件并使用了一些phyton文件.

I am using google app engine as a server, i upload files with google app engine launcher and using some phyton files.

推荐答案

在您的app.yaml中,定义您的静态文件处理程序,如下所示:

In you app.yaml, define your static file handlers like this:

…
handlers:
- url: /static
  static_dir: static
- url: /(.*?)/?
  static_files: \1/index.html
  upload: (.*?)/index.html
…

请注意,由于您是这样定义网站结构的,因此您将无法访问除index.html文件之外的任何其他文件.例如,如果您转到/images/logo.png,则App Engine会尝试通过静态文件images/logo.png/index.html来提供该服务.

Note that because you define your website structure like this, you won't be able to access any other file except the index.html files. For example, if you go to /images/logo.png, App Engine would try to serve that from the static file images/logo.png/index.html.

要解决该问题,您需要将所有静态文件放在不同的子目录中(上例中为/static),并将其用作static_dir.然后,您应该将index.html文件中的文件引用为/static/images/logo.png等.

To fix that problem, you'll need to put all your static files in a different subdirectory (/static in the above example), and serve that as a static_dir. Then you should reference your files from the index.html files as /static/images/logo.png, etc.

更新:我将在此处粘贴您的app.yaml,因为您无法在注释中正确设置其格式:

UPDATE: I'll paste your app.yaml here because you cannot format it correctly in the comment:

handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css|php|xml))
  static_files: \1
  upload: (.*\.(gif|png|jpg|ico|js|css|php|xml))

- url: /robots.txt
  static_files: robots.txt
  upload: robots.txt 

- url: /favicon.ico
  static_files: favicon.ico
  upload: favicon.ico

- url: .*
  script: main.py

- url: /static
  static_dir: static

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

您的问题是- url: .*指令可以捕获所有内容,因此永远不会到达底部的两个处理程序.

Your problem is that the - url: .* directive catches everything so the bottom two handlers are never reached.

此外,您应该考虑在script中使用应用程序引用而不是文件名.不建议提供脚本文件名.

Also, you should consider using an application reference in the script instead of the file name. Providing the script file name is deprecated.

这篇关于在Google App Engine上加载子文件夹时出现错误404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆