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) |
To copy paste that, you would need a site running on Django. If you google around, someone might have already written something similar in PHP, which you could probably just save to a directory on your web server.
Very good - thanks for the quick reply.
Lyle Pratt wrote:
… To copy paste that, you would need a site running on Django. If you google around, someone might have already written something similar in PHP, which you could probably just save to a directory on your web server.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2468246
Thanks for posting this! A few questions...
- This will result in the same content appearing under two URLs: under tumblr.com and under yourdomain.com/blog. Right? I've heard that Google dislikes duplicated content, so doesn't this counteract the SEO benefit somewhat?
- It looks like the code does search-and-replace to make sure all links in the content point to yourdomain.com/blog instead of tumblr. Is that right? Does it work in practice? Are there any links that are missed (e.g. generated by JS, added via Ajax, etc)? Are there URLs that get mistakenly converted (e.g. Images hosted on tumblr servers)?
- Is Tumblr cool with a setup like this? Does it jive with their policies?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Howdy - sorry for being a total noob, but how do I implement this? Just pop it on my web server?