【问题标题】:How to handle trailing slashing in Google App Engine app.yaml如何在 Google App Engine app.yaml 中处理尾部斜线
【发布时间】:2015-10-16 17:46:56
【问题描述】:

我在这里尝试回答这个 SO 问题时遇到了这个问题:Removing PHP file extension when serving PHP files about how to route certain requests in app.yaml for Google App Engine。

但我不知道如何使用单个 app.yaml 正则表达式映射对可能有也可能没有斜杠的 url 的请求。现在,我用两行来处理这个案例:

handlers:
- url: /(.*)/
  script: /\1.php
- url: /(.*)
  script: /\1.php

但这似乎是多余的。这两行可以合二为一吗?

我认为应该可行的事情,比如

url: /(.*)(/?)

url: /(.*)(/{0,1})

url: /(.*)(/?$)

似乎不适用于带有斜杠的请求。

【问题讨论】:

    标签: regex google-app-engine app.yaml


    【解决方案1】:

    使用非贪婪的正则表达式。

    /(.*?)/?$
    

    DEMO

    【讨论】:

      猜你喜欢
      • 2017-02-02
      • 2020-03-19
      • 2014-02-06
      • 2018-04-24
      • 2013-04-09
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 2012-11-06
      相关资源
      最近更新 更多