简体   繁体   中英

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.

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.

Use non-greedy regex.

/(.*?)/?$

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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