Support » Plugins » Hacks » Redirect 301 for facebookexternalhit/1.1

  • Hi all,

    I’m experiencing a strange behavior with Facebook (facebookexternalhit/1.1) using WP 3.2.1. It all started with the Facebook Comments plugin (the one by Alex Moss) which was returning a “unreachable page” error for every single URL on my blog.

    I tried their debug tool (http://developers.facebook.com/tools/debug) to see what was happening exactly. In the end, it seemed that they were getting a permanent redirection (301) for all of my pages.

    Taking a look a my Apache2 log, here’s what I see:

    [12/Aug/2011:14:13:37 -0400] "GET / HTTP/1.0" 301 20 "-" "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"

    I tried to emulate exactly the same request, same user-agent (using cURL) to see what would happen… However, I don’t get a 301, even if the request is exactly the same:

    [12/Aug/2011:14:14:06 -0400] "GET / HTTP/1.0" 206 20 "-" "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"

    In fact, only IP differs! When I try Facebook debug tool on a static url such as WordPress License (license.txt), Facebook is able to reach the page. I’ve done multiple tests, and in the end, I can confirm that for an unknown reason, Facebook gets constantly redirected when trying to access a page served by WordPress.

    For now, what I did is I patched the wp_redirect function in wp-includes/pluggable.php:

    At the beginning of function (Around line 922):


    function wp_redirect($location, $status = 302) {

    if ($_SERVER["HTTP_USER_AGENT"] == "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") {
    die();
    }

    global $is_IIS;

    ...

    It does the trick, but it’s not really clean, so I wanted to know if someone else is experiencing this issue.

    Can it be my theme?

    I tried deactivating all of my extensions, but I was still running into this issue.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • huraaah it works.
    thanks for the solution.

    You’re welcome! 🙂 Glad I could help someone…

    You also gave me an answer; It’s not related to anything from my theme. That was my guess, but honestly, I was too busy (or lazy lol) to dig the issue, so if anyone has more information, feel free to comment!

    Thanks!

    Awesome!
    Thanks so much for this fix!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect 301 for facebookexternalhit/1.1’ is closed to new replies.