简体   繁体   中英

Specifying custom URL schema in appengine using app.yaml?

I am trying to have a custom URL which looks like this:

example.com/site/yahoo.com

which would hit this script like this=

example.com/details?domain=yahoo.com

can this be done using app.yaml?

the basic idea is to call "details" with the input "yahoo.com"

You can't really rewrite the URLs per se , but you can use regular expression groups to perform a similar kind of thing.

In your app.yaml file, try something like:

handlers:
- url: /site/(.+)
  script: site.py

And in your site.py:

SiteHandler(webapp.RequestHandler):
    def get(self, site):
        # the site parameter will be what was passed in the URL!
        pass

def main():
    application = webapp.WSGIApplication([('/site/(.+)', SiteHandler)], debug=True)
    util.run_wsgi_app(application)

What happens is, whatever you have after /site/ in the request URL will be passed to SiteHandler 's get() method in the site parameter. From there you can do whatever it is you wanted to do at /details?domain=yahoo.com, or simply redirect to that URL.

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