gpt4 book ai didi

google-app-engine - 如何使用 Google App Engine 重定向所有 URL

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:59 25 4
gpt4 key购买 nike

如何配置 app.yaml 文件以将所有 URL 重定向到另一个 URL?例如我想要 http://example.appspot.com/hellohttp://example.appspot.com/hello28928723 重定向到 http://example.com.

目前我只提供静态文件。这是我的 app.yaml 文件:

application: testapp
version: 1
runtime: python
api_version: 1

handlers:
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html

- url: /
static_dir: static

最佳答案

Webapp2 有一个内置的重定向处理程序

无需推出自己的处理程序; webapp2 已经自带了一个。

application = webapp2.WSGIApplication([
webapp2.Route('/hello', webapp2.RedirectHandler, defaults={'_uri':'http://example.com'}),
webapp2.Route('/hello28928723', webapp2.RedirectHandler, defaults={'_uri':'http://example.com'}),
], debug=False)

_uri 参数是 RedirectHandler 类用来定义目的地的参数。花了很多 Google Fu 才找到这方面的文档,但它在我的应用程序中完美运行。

我假设你知道这一点,但你需要改变你的包罗万象的路线:

- url: /
static_dir: static

致(python27版):

- url: /.*
script: main.application

或者:(python27之前的版本)

- url: /.*
script: main.py

main.py 是包含请求处理程序和路由的文件。

注意:由于静态文件的性质,在 GAE 上没有处理重定向的纯静态方法。基本上,无法单独在 app.yaml 中进行重定向。

关于google-app-engine - 如何使用 Google App Engine 重定向所有 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1058119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com