I have a text paragraph where it may have external or internal URL. User will enter this text. So, I want external links should add rel=nofollow
and internl links won't be having rel=nofollow
attribute.
Internal links can be:
<a href=http://www.mysite.com"> My Site </a>
or
<a href="/articles/1-world-cup-cricket-2015"> World cup schedule </a>
External link is as usual anything...
My current function is adding rel=nofollow
to all internal and external links.
def add_nofollow html
html.gsub(/\<a href=["'](.*?)["']\>(.*?)\<\/a\>/mi, '<a href="\1" rel="nofollow" target="_new" >\2</a>')
end
The question is how do I add the rel=nofollow to external links only?