2013-01-01 28 views
1

這是我希望用戶能夠共享的網址: http://dealsfortherich.com/product/6379316如何阻止facebook sharer.php忽略來自目標網址的數字?

所以我的應用程序(PHP)構造此URL:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316

如果你看看這個鏈接,你會看到產品編號已被截斷。 Sharer.php是忽略了斜槓(%2F)後的數字 如果我讓這個數字字母數,它的工作原理:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316X

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2FX6379316https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F637X9316

添加尾部的斜線沒有幫助: https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316%2F

很明顯,我可以在我的應用程序中寫一個條件給han這樣的網址: http://dealsfortherich.com/product/6379316X 但是,就搜索引擎而言,我已經複製了內容。

我應該放棄而不使用sharer.php嗎?

+0

順便說一句,我使用PHP來生成這個鏈接服務器端,而不是使用https://developers.facebook.com/docs/reference/plugins/like/,因爲用戶的瀏覽器建立約20個這些按鈕javascript會導致巨大的響應問題(滯後)。 – daSong

+0

如何處理斜線和頁面? '/ index.htm' – arttronics

+0

謝謝,這是一個很好的嘗試...但我的應用程序沒有很好地迴應:http://dealsfortherich.com/product/6379316/index。htm – daSong

回答

0

想通了! 問題是,Facebook並不只是刮頁: http://dealsfortherich.com/product/6379316

facebook object debugger是顯示該刮刀是看到的規範名稱: http://dealsfortherich.com/product/

這是怎麼回事,即使我發出:

remove_action('wp_head', 'rel_canonical'); 

在調用wordpress'get_header()(它又調用wp_head())之前,應該刪除錯誤的規範鏈接。

問題是過濾器fb_meta_tags(來自插件)在OG標記之前添加了一堆OG標記,我認爲這是設置! 果然,標籤beting集之一是:

<meta property="http://ogp.me/ns#url" content="http://dealsfortherich.com/product/" /> 

這是我如何解決它,在我的PHP,get_header前()被調用:

add_filter('fb_meta_tags', 'remove_og_tags'); 
function remove_og_tags($meta_tags) 
{ 
    $meta_tags['http://ogp.me/ns/fb#app_id'] = null; 
    $meta_tags['http://ogp.me/ns#type'] = null; 
    $meta_tags['http://ogp.me/ns#title'] = null; 
    $meta_tags['http://ogp.me/ns#image'] = null; 
    $meta_tags['http://ogp.me/ns#description'] = null; 
    $meta_tags['http://ogp.me/ns#url'] = null; 
    return $meta_tags; 
} 

,阻止錯誤的OG標籤從獲取添加之前,我加入我的:

<link rel="canonical" href="<?php echo $page_path; ?>"/> 
<meta property="fb:app_id" content="xxxxxxxxxxxxx" /> 
<meta property="og:type" content="product" /> 
<meta property="og:title" content="<?php echo $the_title; ?>" /> 
<meta property="og:image" content="<?php echo $image_url; ?>" /> 
<meta property="og:description" content="<?php echo $tweet_text.$the_title; ?>" /> 
<meta property="http://ogp.me/ns#url" content="<?php echo $page_path; ?>" /> 

一切現在正美麗。