【问题标题】:Page for Page Redirect in Google App EngineGoogle App Engine 中的页面重定向页面
【发布时间】:2012-11-24 19:55:45
【问题描述】:

我最近更改了我在 Google App Engine 上运行的 web 应用程序的域名,我想知道是否有一种简单的方法可以将页面从旧网站重定向到新域。代码方面的一切都保持不变,但我只是希望它进入新域。

我正在为 web 应用程序使用 python 和 webapp2 框架。

我知道我可以通过并为每个处理程序做:

webapp2.redirect('the specific url', permanent=True)

但我希望有一个更优雅的解决方案。

【问题讨论】:

  • 你有BaseHandler 还是你所有的处理程序都是webapp2.RequestHandler 的子类?

标签: python google-app-engine redirect dns webapp2


【解决方案1】:

您可以只进行全局 url 重写。基本上,您的 webapp 已经匹配了请求的 URL 并将其定向到 webapp2.WSGIApplication 对象中的适当代码,因此您可以简单地让所有 URL 匹配到相同的 class,可能与 ('/*', myclass) 或类似的东西匹配,并且然后让该页面将用户重定向到新站点的相应页面。示例:

import webapp2
newdomain = 'http://www.mynewdomain.com/'

class RedirectPage(webapp2.RequestHandler):
    def get(self, restofurl):
        return webapp2.redirect(newdomain + restofurl, permanent=True)

app = webapp2.WSGIApplication([webapp2.Route(r'/<restofurl:.*>', handler=RedirectPage, name='redirect_page')])

不幸的是,我目前无法对其进行测试以 100% 确定它是否有效,但我知道它至少在理论上会有效。理想情况下,我更喜欢 Apache URL 重写,但我认为您没有这个选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 2014-10-04
    • 1970-01-01
    相关资源
    最近更新 更多