Created
April 23, 2012 02:05
-
-
Save lylepratt/2468246 to your computer and use it in GitHub Desktop.
Put Your Tumblr Blog in a SubURL (subdirectory) instead of a Subdomain using a Python proxy. It's better to host your blog in a subdirectory rather than a subdomain because Google treats subdomains as totally separate sites which is bad for SEO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def blog(request, url=""): | |
remote = "http://YOURTUMBLRSITE.tumblr.com" | |
local = ""http://www.example.com/blog" | |
conn = httplib2.Http() | |
#This is to support Tumblr's search. | |
if request.GET.get("q"): | |
urlencode = lambda s: urllib.urlencode({'x': s})[2:] | |
url = url+"/"+urlencode(request.GET.get("q")) | |
proxy_url = "%s/%s" % (remote, url) | |
resp, content = conn.request(proxy_url, request.method) | |
p = re.compile('(.+id="content".+)(href|src|rel|action)="\/(.+id="footer".+)', re.DOTALL) | |
content = re.sub(p, r'\1\2="%s/\3' % (local), content) | |
content = content.replace(remote, local) | |
return HttpResponse(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this! A few questions...