我要去基於Ajax構建我的應用程序,和我的網址是這樣的:可抓取的Ajax內容。搜索引擎沒有hashbang。我的路好嗎?
http://server.com/module/#function_name,param1,param2...etc
後引用有關谷歌的建議,一些討論:(#!)hashbang,它不是很難,我認識到,這不是最好的解決方案。有幾個原因:
- 無論如何,該URL是非常醜陋的。
- 如果有一天Google(或其他一些搜索引擎)建議除hashbang以外的更好的解決方案,那將會很糟糕。我必須使用hashbang來保存我的醜陋URL,或者寫一些js代碼來使我的頁面鏈接仍然活着。
- HTML5 pushState有一天會很受歡迎。
對於以上所有的東西,我決定把我的方法:我的導航鏈接將是這樣的:
<a href="http://server.com/module/for-crawler/function-name/param1/param2/...">
Some text </a>
而且一些jQuery代碼將使它能夠加載的AJAX內容,而不是頁面級改變像一個正常的鏈接:
$(function(){
$('a').live('click',function(e){
var realURL = translateURL($(this).attr('href'))
loadContent(realURL);
e.prevetnDefault();
return false;
})
})
/* -- the function translateURL will turn url like :
..... http://server.com/module/for-crawler/function-name/param1/param2/...
Into:
..... http://server.com/module/#function-name/param1/param2/...
That's the real url I think all ajaxers are used to dealing with
*/
當履帶式讀取我的網頁,它會跟在「href」屬性的網址,我會爲它提供靜態的非js版我的網頁只爲谷歌閱讀。過了些日子,我的網頁被收錄&用戶將看到谷歌的結果,這樣我的網頁:
http://server.com/module/for-crawler/function-name/param1/param2/...
我要用戶再次JS把用戶重定向到我的正常AJAX版本,我的意思是,真正的網址:
http://server.com/module/#function-name/param1/param2/...
這是我現在可以考慮的最佳方法。請給我建議:我應該這樣做,還是我可以做得更好?感謝所有人!
當搜索引擎看看你的網址,他們會認爲你的網站有多個目錄,他們可能不會打擾到很遠。搜索引擎甚至需要擔心你的參數,你的網址不能像「/功能名稱?someparam&anotherparam –
@MatthewRiches:我的網址只是爲了演示,它可以是斜線「/」或任何東西來分隔我的參數。 –