質問

I have a simple Django site, with 2 pages. It is kind of like those stupid buzzfeed quizzes. There is a questions page (www.mypage.com), and a results page (www.mysite.com/results/myResults). I am trying to use the facebook share button to drive social sharing. I want people to share the results page (e.g. "I got this result, what about you?"), but I need incoming users clicking these shared links to be redirected to the main questions page.

I have tried adding a URL parameter www.mysite.com/results/myResults?fromShare = T and using a view to redirect these to the main page. However, the facebook crawler also gets redirected, so the shared content ends up being the main page, rather than the individualized results page.

tl;dr: how do I redirect incoming human users, while not redirecting the facebook crawler? I would ideally like to do this in a django view, rather than .htaccess.

役に立ちましたか?

解決

Facebook user agent will be one of these:
facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.0 (+http://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.0 (+https://www.facebook.com/externalhit_uatext.php)

Look for these in request.META['HTTP_USER_AGENT'] and redirect.

他のヒント

In your view, look at request.META['HTTP_USER_AGENT'], compare it to Facebook crawler's, and redirect if it doesn't match. If it does match, serve your page template.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top