I want to add rel="nofollow"
attribute in all my external links. Below code works well on links comes with http://
and https://
. my problem is its not worked on links without http
(ex: /somepage.html
) how can i over come this.
Any solution highly appreciated.
HTML
<a href="http://www.somepage.com">This is an internal link</a>
<br /><br />
<a href="http://google.com">And this is an external link, with no follow (working)</a>
<br />
<br />
<a href="google.com">And this is an external link, with no follow (not-working)</a>
<br />
<br />
<a href="https://plus.google.com/101147114025225446015/about">And this is an external link, with no follow (working)</a>
JS
jQuery('a[href*="http://"]:not([href*="http://www.somepage.com"])').attr('rel', 'nofollow');
jQuery('a[href*="https://"]:not([href*="http://www.somepage.com"])').attr('rel', 'nofollow');
jQuery('a[href*="https://"]:not([href*="https://www.somepage.com"])').attr("target", "_blank");