开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜