Search code examples
.htaccessurlurl-rewritingfacebook-likevbulletin

Like Button, vBulletin and Mod Rewrite


I'm having a really, really, really weird problem on my vBulletin board using Facebook's Like Button. In my thread template I'm using the following code, which is located inside body tag:

<td class="vbs_forumdata alt1">
    <div id="fb-root"></div>
        <script type="text/javascript">(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src="//connect.facebook.net/en_US/all.js#xfbml=1";fjs.parentNode.insertBefore(js,fjs)})(document,"script","facebook-jssdk");</script>
        <div id="thread_sharing_content_facebook">
            <div class="fb-like" data-href="{vb:raw sharingurl}" data-layout="button_count" data-send="false" data-show-faces="false" data-width="90"></div>
        </div>
    </div>
</td>

As soon as the template is processed by the vBulletin engine, the variable {vb:raw sharingurl} is replaced by the thread's canonical URL, that looks like this:

http://MYDOMAIN/threads/THREADID-THREADTITLE

For example:

http://www.mydomain.com/threads/1-Hello-Community

Looking at the HTML source of a thread page, everything seems to work as intended:

<td class="vbs_forumdata alt1">
    <div id="fb-root"></div>
        <script type="text/javascript">(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src="//connect.facebook.net/en_US/all.js#xfbml=1";fjs.parentNode.insertBefore(js,fjs)})(document,"script","facebook-jssdk");</script>
        <div id="thread_sharing_content_facebook">
            <div class="fb-like" data-href="http://www.mydomain.com/threads/1-Hello-Community" data-layout="button_count" data-send="false" data-show-faces="false" data-width="90"></div>
        </div>
    </div>
</td>

But then, if I click on the Like Button to share the thread page... here comes the drama:

Drama

The original URL of the thread page is messed up transformed into something like:

http://MYDOMAIN/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/THREADID-THREADTITLE

Anyone knows why I'm getting that strange problem? The only thing I was thinking about trying to figure it out by myself, is my htaccess file which contains some rewrite rules. It's almost the vBulletin default one... but, anyway, here they are:

RewriteEngine On
RewriteBase /

// Block Bad Bots
RewriteCond %{HTTP_USER_AGENT} [...]
RewriteRule ^.*$ - [F,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^forums/.* forumdisplay.php [QSA]
RewriteRule ^members/.* member.php [QSA]
RewriteRule ^threads/.* showthread.php [QSA]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(?:(.*?)(?:/|$))(.*|$)$ $1.php?r=$2 [QSA]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [NC,L]

RewriteRule ^(.*)$ - [R=404,L]

EDIT: I tried using the Facebook URL debugger and...

Scrape Information

Response Code: 200
Fetched URL: http://www.mydomain.com/threads/1-Hello-Community
Canonical URL: http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community

Critical Errors That Must Be Fixed

Could Not Follow Redirect Path: Using data from http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community because there was an error following the redirect path.

Errors That Must Be Fixed

Too Many Redirects: URL redirected too many times. Please reduce the number of redirects.

Like Button Warnings That Should Be Fixed

Admins And App ID Missing: fb:admins and fb:app_id tags are missing. These tags are necessary for Facebook to render a News Feed story that generates a high click-through rate.
Like Button Tag Missing: og:title is missing. The og:title meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.
Like Button Tag Missing: og:type is missing. The og:type meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.
Like Button Tag Missing: og:image is missing. The og:image meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.

Open Graph Warnings That Should Be Fixed

Inferred Property: The 'og:url' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The 'og:title' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The 'og:description' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The 'og:image' property should be explicitly provided, even if a value can be inferred from other tags.

Object Properties

og:url: http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
og:type: website
og:title: #Page Title#
og:image: 
og:description: #Meta Description#
og:updated_time: 1348134967

Redirect Path

originale: http://www.mydomain.com/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community

Final URL is in bold (this is the URL we tried to extract metadata from).

Please, please, PLEASE... help me out!


Solution

  • You may need to add the meta og tag

     <meta type="og:url" content="<?php get_current_url(); ?>" >
    

    try it