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

孤街浪徒 提交于 2019-12-01 06:33:52

问题


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.

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. 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.


回答1:


Use non-greedy regex.

/(.*?)/?$

DEMO



来源:https://stackoverflow.com/questions/31637884/how-to-handle-trailing-slashing-in-google-app-engine-app-yaml

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