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

拟墨画扇 提交于 2019-12-24 18:47:33

问题


I uploaded my webpage using google app engine and it is working fine. It is a very simple webpage with 6 static files (.html all of them)

I need to Remove .html extension from URL. For example: I have www.example.com/contact.html, I want www.example.com/contact

My current app.yaml is

runtime: php55
api_version: 1
threadsafe: true

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

- url: /
  static_dir: website

All html files are Inside the "Website" folder, so how can i hide .html extension from URL

So Please help me to fix it.


回答1:


If you have just 6 static files and you do not want to use .htaccess, you have to do this:

Instead of

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

You could:

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



回答2:


You could try something like this, but you'll have to not rely on the existing catch-all static_dir handler you have at the end, since that will never be reached due to the new catch-all handler expanding any other file pattern with a .html extension:

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

# handler for specifically requested .html files
- url: /(.*\.html)$
  static_files: website/\1
  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/\1.html
  upload: website/.*\.html$

# no other handler from this point forward will be reached

Side note: overlapping handler url patterns for static_dir and static_files may cause problems, see Static files are missing



来源:https://stackoverflow.com/questions/51467971/how-to-hide-html-extension-in-url-from-google-app-engine-cloud-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!