2017-11-08 5 views
0

すべての外部リンクにrel = "nofollow"属性を適用したいのですが、私の機能のような内部リンクがなく、実装方法がわかりません。私の内部リンクにnofollow属性を追加

私の2番目の質問:JavaScriptを使用してrel = "nofollow"を追加する必要はありません。検索エンジンは一般にJavaScriptを実行しません。

<div class="post"> 
     <h2 class="post title" > 
      <a href="https://www.exemple0.com/" title="web site" ></a> 
     </h2> 
    </div> 
    <div class="post"> 
     <h3 class="post title" > 
      <a href="https://www.exemple1.com/" title="web site" ></a> 
     </h3>  
     <li class="tags"> 
      <span class="tag"><span class="tel">hello</span><br> 
      <a target="_blank" href="http://www.exempleInternal.com"> internal</a> 
     </li> 
    </div> 
    <div class="post"> 
     <h4 class="post title" > 
      <a href="https://www.exemple2.com/" title="web site" ></a> 
     </h4> 
    </div> 
    <script > 

    $(document).ready(function() { 
    (function($){ 
       $('a').each(function(){ 
        $(this).attr('rel', "nofollow"); 
       }); 
      }); 
    }) 
    </script> 
+0

GoogleはJavascriptを実行します。また、内部リンクではnofollowを使用しないことをお勧めします。それはあなたを傷つけるだけです。 –

+0

ほとんどの検索エンジンはページ全体を解決しません。だから、Javascriptで追加するのは無駄だ。私はGoogleがそうしていると聞きましたが、サイトが変わっているのではなく、サイトが変わっていない場合があります。 – Forbs

+0

ありがとう、私の機能のようなものにnofollowを追加できますか?手動で...できますか? –

答えて

0

hrefタグのURLを確認し、rel = nofollowを追加することができます。

$('a[href^="http"]:not([href^="http://www.example.com"],[href^="http://example.com"])').add('a[href^="www"]:not([href^="www.example.com"])').attr('rel', "nofollow") 

あなたのドメイン名である必要がある 'example.com'を持たないすべてのリンクにrel = nofollowが追加されます。

関連する問題