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

I ran into this problem while trying to answer this SO question here: Removing PHP File Extension When Working With PHP Files on how to redirect specific requests to app.yaml for Google App Engine.

But I couldn't figure out how to match requests for URLs that may or may not have a trailing slash with a single app.yaml regex. Right now, I am handling this case with two lines:

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

      

But that seems like overkill. Can these two lines be combined into one?

Things that I thought should work like

url: /(.*)(/?)

      

and

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

      

and

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

      

don't seem to work for requests with trailing slashes.

+3


source to share


1 answer


Use a non-greedy regular expression.

/(.*?)/?$

      



DEMO

+6


source







All Articles