Juliette Foucaut - 20 Jun 2014
In this post I'll describe how to use Google App Engine to masked redirect a URL to a desired domain. Our proposed method of URL redirection involves a python script using the webapp2 framework running server-side on GAE. As a result of this setup, you can have visitors requesting content from one domain, say www.new-url.com, see content which is hosted on another such as www.old-url.com.
The way it works is as follows: GAE is configured to use www.new-url.com as a custom domain. Whenever a visitor requests a page from www.new-url.com, GAE fetches the data from www.old-url.com, then forwards it. To the visitor, the page effectively comes from www.new-url.com. This is particularly useful if you have content hosted in a service which doesn't allow you to set up the custom domain you want.
it's a workaround for the fact that Google Sites does not allow masked redirect using a frame.
free if you already use Google Apps for Business.
If you'd like to support us, you can use our referral link to try Google Apps for business.
whilst Google App Engine is free to use within limited parameters, to set up a custom domain, you need Google Apps for Business.
increased server overhead - both the content hosting site and GAE have to serve the content. This can be resolved with caching (not covered in this post).
as with any masked redirection, the original website still exists and is publicly available - however in some cases you might be able to setup permissions on the content server such that only the GAE app can access the content.
if the original website contains absolute links, code should be added to the python script to parse the html on the fly and update those links to refer to the new domain.
Create a Google App Engine application with two files: app.yaml and redirect.py.
Paste the code below in app.yaml:
application: masked-redirect version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /.* script: redirect.application libraries: - name: webapp2 version: "2.5.2"
Paste the code below in redirect.py, replacing www.old-url.com with your value:
import webapp2 from google.appengine.api import urlfetch class MainPage(webapp2.RequestHandler): def get(self): url = "http://www.old-url.com" + self.request.path_qs result = urlfetch.fetch(url) self.response.out.write(result.content) application = webapp2.WSGIApplication([(r'.*', MainPage),], debug=True) def main(): application.run()
Upload the files to Google App Engine and ensure the application is running.
Follow the GAE instructions to set up the custom domain www.new-url.com.