如何从 google 应用引擎(云托管)中隐藏 URL 中的 .html 扩展

how to hide .html extension in URL from google app engine (cloud hosting)

我使用 google 应用引擎上传了我的网页,它运行良好。这是一个非常简单的网页,有6个静态文件(.html全部)

我需要从 URL 中删除 .html 扩展名。 例如:我有www.example.com/contact.html,我要www.example.com/contact

我现在的app.yaml是

runtime: php55
api_version: 1
threadsafe: true

handlers:
- url: /
  static_files: website/index.html
  upload: website/index.html

- url: /
  static_dir: website

所有 html 文件都在 "Website" 文件夹中,那么如何隐藏 URL

的 .html 扩展名

所以请帮我解决它。

您可以尝试这样的事情,但您将不必依赖现有的包罗万象的 static_dir 处理程序,因为新的包罗万象-所有处理程序扩展任何其他具有 .html 扩展名的文件模式:

handlers:
- url: /
  static_files: website/index.html
  upload: website/index.html

# handler for specifically requested .html files
- url: /(.*\.html)$
  static_files: website/
  upload: website/.*\.html$

# add any other more specific file patterns here, before the catch-all case below

# catch-all handler implicitly serving .html files, no handler below it will be reached
- url: /(.*)$
  static_files: website/.html
  upload: website/.*\.html$

# no other handler from this point forward will be reached

旁注:static_dirstatic_files 的重叠处理程序 url 模式可能会导致问题,请参阅

如果您只有 6 个静态文件并且不想使用 .htaccess,则必须这样做:

而不是

> handlers:
> 
> - url: /   static_dir: website

你可以:

handlers:

- url: /
  static_files: website/index.html
  upload: website/index.html

- url: /file1
  static_files: website/file1.html
  upload: website/file1.html

- url: /file2
  static_files: website/file2.html
  upload: website/file2.html

- url: /file3
  static_files: website/what_ever_name.what_ever_format
  upload: website/what_ever_name.what_ever_format