简体   繁体   English

如何在Google App Engine app.yaml中处理尾随削减

[英]How to handle trailing slashing in Google App Engine app.yaml

I ran into this problem trying to answer this SO question here: Removing PHP file extension when serving PHP files about how to route certain requests in app.yaml for Google App Engine. 我遇到了这个问题,试图回答这个问题: 在提供有关如何在app.yaml中为Google App Engine路由某些请求的PHP文件时删除PHP文件扩展名

But I couldn't figure out how to map requests for urls which may or may not have a trailing slash with a single app.yaml regular expression. 但我无法弄清楚如何映射URL的请求,这些URL可能有也可能没有带有单个app.yaml正则表达式的尾部斜杠。 Right now, I'm handling that case with two lines: 现在,我用两行来处理这个案子:

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

But that seems redundant. 但这似乎是多余的。 Can these two lines be combined into one? 这两条线可以组合成一条吗?

Things I thought should work, like 我认为应该工作的东西,比如

url: /(.*)(/?)

and

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

and

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

don't seem to work for requests with the trailing slash. 似乎不适用于带有斜杠的请求。

Use non-greedy regex. 使用非贪婪的正则表达式。

/(.*?)/?$

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM