如何正则表达式在谷歌App Engine的静态网页?(How to Regex for static

2019-11-03 01:03发布

我有一个静态网站,我想上传到谷歌Apps的,我有正则表达式侧麻烦,想一些帮助,无论是解释我做了什么错或指向我的资源可能帮助。

下面是我到目前为止已经完成:

网站结构

  • 我的静态站点(不是我真正的应用程序名)
    • DIST
      • 关于
      • 博客
        • 后1
          • 的index.html
      • 图片
      • 项目
        • 项目1
          • 的index.html
      • 脚本
      • 款式
      • about.html
      • archives.html
      • 的index.html
      • project.html

app.yaml的代码

application: my-static-site
version: 1
runtime: python27
api_version: 1
threadsafe: no

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

- url: /
  static_dir: dist

# to load my-static-site.appspot.com/project/project-1
- url: /project/project-1/
  static_files: dist/project/project-1/index.html
  upload: dist/project/project-1/index.html

# to load my-static-site.appspot.com/blog/post-1
- url: /blog/post-1/
  static_files: dist/blog/post-1/index.html
  upload: dist/blog/post-1/index.html

如何表现

要my-static-site.appspot.com显示正确的主页与造型,剧本等。

点击担任“后1”在博客中部分链接重定向到my-static-site.appspot.com/blog/post-1/并呈现黑屏,所以index.html的不被显示在这里。 这是该项目的一节“项目1”链接相同。

但是,如果我手动添加的index.html到博客网址的任何项目,内容服务。 例如my-static-site.appspot.com/blog/post-1/index.html正确地显示。

我究竟做错了什么?

谢谢!

Answer 1:

Played around and found order matters in Regex, this is what works:

application: my-static-site
version: 2
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /(.+)/(.+)/
  static_files: dist/\1/\2/index.html
  upload: dist/(.+)/(.+)/index.html

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

- url: /
  static_dir: dist

Locally the blog posts and project posts with url /blog/post-1 and /project/project-1 serve the index.html file in each dir.

If anyone has a more elegant solution feel free to chime in.



文章来源: How to Regex for static webpage on Google App Engine?