2009-12-21 91 views
1

在我的網站上,我的搜索框與谷歌中心,當你搜索的東西,它顯示所有符合搜索條件的線程。簡單的Ajax + SEO解決方案?

所以這些線程都是ajaxad,但是當你點擊一個線程時,它會通過常用的href鏈接進入線程內容,頁面將刷新。

現在我必須讓谷歌找到這些鏈接鏈接到每個線程以通常的方式,所以如果我把'顯示所有線程'鏈接在我的第一頁右上角顯示我的每一個線程網站,它解決了SEO部分?

谷歌是能夠索引他們所有,但用戶將只使用阿賈克斯搜索框?

我讀過「只要谷歌可以從第一頁(index.php)中找到所有內容就好了」。所以這將是一個很好的解決方案?

回答

3

AJAX的一個缺點是它打破了網絡的一個基本方面:任何訪問給定URL的人都將獲得相同的頁面視圖。這意味着書籤功能無法正常工作(或根本不能),鏈接共享也無法正常工作。這也意味着機器人(甚至是非常聰明的機器人)可能會錯過整個網站的所有部分。

解決此問題的一種方法是確保您的所有內容均可通過非AJAX方式訪問。 優雅的降級是一個重要的設計概念,但事實上可能很難實現。我的規則是讓網站在沒有任何JS魔法的情況下正常工作,然後在JS啓用的情況下使其更加鮮明。從可訪問性的角度來看,這也很好,因爲許多有障礙的人不能從AJAX和其他JS巫術中受益(或實際上進一步處於劣勢)。

+0

,但不能解決URL部分與真正簡單的歷史或谷歌ajax Webkit? – ajsie 2009-12-21 15:40:39

+0

簡答題:否。如果訪問站點中某個特定位置所需的所有信息都不在URL中,那麼您已經違反了REST合同。請參閱http://en.wikipedia.org/wiki/Representational_State_Transfer。建立一個並不假裝爲RESTful的網站(例如Google地圖)是很好的,但這樣做意味着您違反了所有蜘蛛/搜索引擎的基本假設。這還包括使用cookie來存儲狀態 - 大多數索引機器人不會確認cookie。 – 2009-12-21 15:52:57

1

這會起作用 - 達到某一點 - 你最好把鏈接放在不同的頁面上。你可以相信你的用戶會走上阻力最小的道路。如果你的搜索比你的列表更好,你會在那裏很好。

關於谷歌,你所描述的聽起來很像一個網站地圖。這樣可以正常工作,但是如果超過150個鏈接(大約是searchbot放棄的時間),請考慮將其分成多個頁面。該頁面也應該不是index.php,然後在主頁上提供一個鏈接。許多新聞網站按天或周分類,但您也可以使用字母或其他。使用最適合您網站的系統。

1

在您的網站上關閉JavaScript。你能以某種方式導航到線程嗎?如果是這樣,你可以假設Google也可以。

我必須假設你的網站不完全依賴搜索來尋找線程。應該有某種傳統的以類別爲基礎的方式去論壇。如果是這樣,那應該是所有Google需要的。

更糟的情況是什麼?是的,一個鏈接到某種所有職位索引的鏈接也應該可以工作。

+0

其後一個:)所以爲什麼很多人抱怨ajax + seo掙扎時,你可以很容易地解決它呢?或者我錯過了什麼? – ajsie 2009-12-21 15:37:09

-2

這裏是完整的Web示例與Php,Apache,Ajax,history.js(支持書籤和後退前進)和SEO支持沒有散列(#)或查詢(?):http://solusiprogram.com/ajax-seo-with-back-forward-support/

現場演示是網站本身。只需嘗試用JavaScript打開或關閉(遵守SEO)。

然後這裏有鏈接的內容:

  • 全部替換「yourdomain.com」下文提到的與你
  • 下面提及到Apache文檔根目錄
  • 下載jquery-把所有的文件1.11.1.min.js
  • 下載browserstate-history.js-1.8-20-gd213d8c.tar.gz然後把這些 的3個文件到您的文檔根目錄:

    • 腳本/壓縮/ history.js
    • 腳本/壓縮/ history.adapter.jquery.js
    • 腳本/捆綁/ HTML4 + HTML5/jquery.history.js
  • 創建的.htaccess

    #if server returns error, remove this line as your hosting server already handles it 
    Options +SymLinksIfOwnerMatch 
    RewriteEngine On 
    RewriteBase/
    
    #these 3 parts below avoiding duplicate contents that SEO doesn't like 
    
    #enforce non-www-uri (you can modify it if you want www-uri instead) 
    RewriteCond %{HTTP_HOST} ^www.yourdomain\.com$ [NC] 
    RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301] 
    #remove trailing index.html or index.php 
    RewriteCond %{THE_REQUEST} /index\.(html|php)\ HTTP/ 
    RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [L,R=301]  
    #enforce a trailing-slash 
    RewriteRule ^([^.]*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301]  
    
    #set your home page as the default page 
    Rewriterule ^$ http://%{HTTP_HOST}/home/ [L,R=301]  
    #to achieves SEO friendly without querystring uri 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    Rewriterule ^([^?]*)/?$ /index.php?page=$1 [NC,L,QSA]
  • 創建的index.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> 
    <head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <?php 
    $base_uri = "http://yourdomain.com/"; 
    $menus[] = array('href'=>'home' , 'title'=>'Home Page' , 'display_text'=>'Home'); 
    $menus[] = array('href'=>'page1', 'title'=>'Page 1' , 'display_text'=>'Page 1'); 
    $menus[] = array('href'=>'page2', 'title'=>'Page 2' , 'display_text'=>'Page 2'); 
    $page_query = trim($_GET['page'], '/'); 
    $page = 'home'; $title = 'Home Page'; //the default page to display 
    $menu_display = ''; 
    foreach($menus as $menu) { 
        $menu_display .= '<li><a href="' .$base_uri.$menu['href']. '/" title="' .$menu['title']. '">' .$menu['display_text']. '</a></li>'; 
        if($menu['href'] == $page_query) { //set page to display based on url query 
         $page = $page_query; 
         $title = $menu['title']; 
        } 
    } 
    echo '<title>' .$title. '</title>'; //php set page title for the first load of this index.php then History will replace it when user clicks a menu or back/forward browser button 
    ?> 
    <script src="http://yourdomain.com/jquery-1.11.1.min.js" type="text/javascript"></script> 
    <script src="http://yourdomain.com/jquery.history.js"></script> 
    <script type="text/javascript"> 
    //<![CDATA[ 
        jQuery(document).ready(function() { 
         if(document.location.protocol === 'file:') alert('The HTML5 History API (and thus History.js) do not work on files, please upload it to a server.'); 
         var last_url = ""; 
         var History = window.History; 
         //intercept the menu click event 
         $('li>a').click(function() { 
          $(this).onclick = undefined; //to prevent default anchor event >> thanks to http://stackoverflow.com/users/690854/thecodeparadox 
          var data = {}; data.putYour = "data here if you need to"; 
          //push the data, url & title to History and then History.Adapter will load the url 
          History.pushState(data, $(this).attr('title'), $(this).attr('href')); 
          return false; 
         }); 
         //History.adapter triggered by pushState() above or by back/forward browser button 
         History.Adapter.bind(window,'statechange',function() { 
          var State = History.getState(); 
          var data = State.data; //all the data you passed on pushState() above is accessable here now, then you can do whatever you need 
          var url = State.url; 
          url = url.replace(/\/$/,''); //remove trailing slash 
          if(url==last_url) return; //prevent ajax from loading the same last_url 
          last_url = url; 
          if(!(/.html$/i.test(url))) url=url+'.html'; //make sure it ends with '.html' 
          //alert("ajax will load page: '" + url + "'"); 
          $("#ajax_target").load(url); 
         }); 
        }); 
    //]]> 
    </script> 
    <style type="text/css"> 
        body { margin:2em; } 
        #menu { border: 3px solid #DDD; } 
        ul { 
         margin:1em; 
         background:#DDD; 
        } 
        li { 
         list-style-type: none; 
         background:white; 
         padding:5px 13px; 
        } 
        #ajax_target { 
         text-align: center; 
         vertical-align: middle; 
         padding:3em; 
         border: 3px solid #DDD; 
        } 
    </style> 
    </head> 
    <body> 
    <h1>AJAX SEO by solusiprogram.com</h1> 
    <h3>- support SEO uri without hash (#) or query (?)</h3> 
    <h3>- can run normally without javascript to comply SEO</h3> 
    <h3>- support Browser History Feature (Back/Forward Buttons)</h3> 
    <h3>- the uri and Page's Title changed as content changed</h3> 
    <h3>- support Html4 and Html5 Browser</h3> 
    <div id="menu"> 
        <ul> 
         <?php echo $menu_display; ?> 
        </ul> 
    </div> 
    <div id="ajax_target"> 
        <?php require($page . '.html'); ?> <!-- php fill ajax_target for the first load of this index.php then History.Adapter will replace it when user clicks a menu or back/forward browser button --> 
    </div> 
    </body> 
    </html> 
            
  • 創建home.html的

    This is Home Page
  • 創建page1.html

    This is Page 1
  • 創建page2.html

    This is Page 2
  • 創建sitemap.xml的

    <?xml version="1.0" encoding="UTF-8"?> 
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 
    
    <url> 
        <loc>http://yourdomain.com/home/</loc> 
        <changefreq>daily</changefreq> 
    </url> 
    <url> 
        <loc>http://yourdomain.com/page1/</loc> 
        <changefreq>daily</changefreq> 
    </url> 
    <url> 
        <loc>http://yourdomain.com/page2/</loc> 
        <changefreq>daily</changefreq> 
    </url> 
    </urlset>
  • 建立robots.txt

    User-agent: * 
    Disallow: 
    Sitemap: http://yourdomain.com/sitemap.xml
  • 現在你可以試着 「HTTP [:] // yourdomain.com/」 與JavaScript的轉彎或關閉(以符合搜索引擎優化)。

+0

歡迎您訪問解決方案的鏈接,但請確保您的答案在沒有它的情況下很有用:[添加鏈接上下文](// meta.stackexchange.com/a/8259),以便您的同行用戶瞭解它是什麼以及爲什麼它在那裏,然後引用您鏈接的頁面中最相關的部分,以防目標頁面不可用。 [僅僅是一個鏈接的答案可能會被刪除。](// stackoverflow.com/help/deleted-answers) – 2017-03-24 11:30:48