在没有尾随/文件夹的情况下添加服务HTML

时间:2012-06-03 15:03:39

标签: google-app-engine

我似乎无法在任何地方找到它。

我所拥有的只是提供html页面的appengine项目。但它只在文件名“完全”正确时才正确加载文件。

即。 mywebsite.com/lastproject/完美加载

mywebsite.com/lastproject根本没有加载

我希望在尾随/遗漏时正确加载网站。我错过了什么?

这是我的app.yaml

application: websitewithsubfolder
version: 1
runtime: python
api_version: 1

handlers:

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

- url: /
  static_dir: static

2 个答案:

答案 0 :(得分:0)

您在yaml文件中的第一个映射告诉AppEngine“每个以/结尾的URL应该映射到...”。您没有任何映射到不以/.

结尾的内容

这会将所有内容映射到名为static / html的文件夹(未经测试,如果有效,请告诉我)

- url: /.*
  static_dir: static/html
  mime_type: text/html

答案 1 :(得分:0)

@Shay表示该行应为:

- url: (.*)

这是一条处理所有URL请求的路由,您不会收到任何404错误,所有请求都由 static index.html页面处理。您的第二条路线将不会被处理,因为它更具体,并且在您的通用路线之后。

您希望捕获所有路线之上的更具体路线。

application: websitewithsubfolder
version: 1
runtime: python
api_version: 1

handlers:
- url: /static
  static_dir: static

- url: /favicon.ico
  static_files: static/images/favicon.ico
  upload: static/images/favicon.ico
  mime_type: image/vnd.microsoft.icon

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

- url: /(.*\.(gif|png|jpg))
  static_files: \1
  upload: (.*\.(gif|png|jpg))

- url: /static/css
  static_dir: static/css

- url: /static/js
  static_dir: static/js

- url: (.*)
  static_files: static/index.html
  upload: static/index.html

上面的app.yaml文件更符合您的要求。

我建议您阅读更详细的app.yaml文档。