如何从appspot域重定向到自定义域?

发布于 12-24 02:22 字数 506 浏览 2 评论 0原文

我发现 Amir 发表了有关将请求从 google.appspot 域重定向到自定义域的帖子。我的问题是你使用 Web2py 将这样的东西放在哪里?

**To just add a custom domain, just follow the instructions here: http://code.google.com/appengine/articles/domains.html
And once that works, you can put a check in your code to forward anyone landing on the appspot.com domain to your domain: (example in python)
def get(self):
  if self.request.host.endswith('appspot.com'):
    return self.redirect('www.jaavuu.com', True)
  # ... your code ...**

I found this post from Amir in regards to redirecting request from google.appspot domain to the custom domain. My question is where do you put something like this using Web2py?

**To just add a custom domain, just follow the instructions here: http://code.google.com/appengine/articles/domains.html
And once that works, you can put a check in your code to forward anyone landing on the appspot.com domain to your domain: (example in python)
def get(self):
  if self.request.host.endswith('appspot.com'):
    return self.redirect('www.jaavuu.com', True)
  # ... your code ...**

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心清如水2024-12-31 02:22:53

在第一个模型文件的开头,您可以执行以下操作:

if request.env.http_host.endswith('appspot.com'):
    redirect(URL(host='www.yourdomain.com', args=request.args, vars=request.vars))

这将保留整个原始 URL,但将 yourdomain.appspot.com 替换为 www.yourdomain.com 除外。请注意,URL() 将自动填充当前控制器和函数,但您必须显式传递当前 request.args 和 request.vars 以确保它们得到保留。

At the beginning of your first model file, you can do:

if request.env.http_host.endswith('appspot.com'):
    redirect(URL(host='www.yourdomain.com', args=request.args, vars=request.vars))

This will preserve the entire original URL, except for replacing yourdomain.appspot.com with www.yourdomain.com. Note, URL() will automatically fill in the current controller and function, but you have to explicitly pass the current request.args and request.vars to make sure they get preserved.

别挽留2024-12-31 02:22:53

这将进入您的请求处理程序。

使用 web2py 文档 中的示例:

示例 8

在控制器中:simple_examples.py

def redirectme():
    redirect(URL('hello3'))

你想做这样的事情:

def some_function():
    if request.env.http_host.endswith('appspot.com'):
        redirect(URL('www.yourdomain.com'))

That goes into your request handler.

Using example from web2py documentation:

Example 8

In controller: simple_examples.py

def redirectme():
    redirect(URL('hello3'))

You'd want to do something like this:

def some_function():
    if request.env.http_host.endswith('appspot.com'):
        redirect(URL('www.yourdomain.com'))
梦里南柯2024-12-31 02:22:53

对于 webapp2,这与我所做的类似,其中 BaseHandler 是我所有处理程序的类型:

class BaseHandler(webapp2.RequestHandler):
    def __init__(self, request, response):
        self.initialize(request, response)
        if request.host.endswith('appspot.com'):
            query_string = self.request.query_string
            redirect_to = 'https://www.example.com' + self.request.path + ("?" + query_string if query_string else "")
            self.redirect(redirect_to, permanent=True, abort=True)

With webapp2 here is something like what I did, where BaseHandler is the type of all my handlers:

class BaseHandler(webapp2.RequestHandler):
    def __init__(self, request, response):
        self.initialize(request, response)
        if request.host.endswith('appspot.com'):
            query_string = self.request.query_string
            redirect_to = 'https://www.example.com' + self.request.path + ("?" + query_string if query_string else "")
            self.redirect(redirect_to, permanent=True, abort=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文