Sometimes its the simplest things that trip me up.
I have an application running on App Engine that utilizes subdomains. I'd like to redirect to different HTML pages depending o开发者_开发百科n whether a subdomain is being used or not.
For example, if a user tries to sign up for a new account through a subdomain, this doesn't make a whole lot of sense, so I'd like to redirect to the signup page on the promary domain:
user_subdomain.main_domain.com/signup_for_new_account.html ----redirect to--> main_domain.com/signup_for_new_account.html
I discussed subdomain routing here. In a nutshell, you can write your own (fairly simple) WSGI middleware that takes care of routing different subdomains to different WSGI applications.
In Python you can check os.environ['SERVER_NAME'] == 'main_domain.com'
, then redirect.
For Java I think the request has a getServerName
method that returns the server name. Then you can redirect, which basically means setting a few headers and returning.
You can do this client-side with javascript:
if (location.hostname !== 'main_domain.com') {
location.href = 'http://main_domain.com' + location.pathname;
}
Doing the same thing server-side is trickier.
Routing is handled based on the path only, not the hostname. Within app.yaml, it's not possible to assign different handlers to the same path on different hostnames. You would need to point /signup_for_new_account.html to a dynamic handler that first checks the hostname and then either issues a redirect or proxies to the static content.
精彩评论