2010-06-09 35 views

回答

4

你真的不能重寫這些URL 本身,但你可以使用正則表達式組來執行類似的樣的東西。

在你的app.yaml文件,你可以試試:

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

而在你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) 

會發生什麼情況是,無論你在請求URL /site/後有會在site參數中傳遞給SiteHandlerget()方法。從那裏你可以做任何你想做的/details?domain=yahoo.com,或只是重定向到該網址。

+0

完美答案!非常感謝你的回覆。 – demos 2010-06-09 07:13:37

+3

請注意,app.yaml中的正則表達式可以是任何匹配的東西,並且它不需要捕獲元素。通常,您只需使用。*將所有內容發送到您的腳本,並在您的WSGI應用程序中使用更具體的正則表達式(使用捕獲元素)。 – 2010-06-09 09:06:24