HtmlPurifier Adding nofollow to ALL links Not Just External

0
149
Asked By Chris Evans On

I am using HTMLPurifier for PHP to ensure that all external links in a piece of HTML that the user provides have the nofollow tag. The problem Is that when I run the code, it will make all links nofollow, including those for my own domain. How are you supposed to make just external links and not the internal links for your own website?

1 Answer

Answered By Elli Mongillo On

You will need to provide the code to give an idea of what is going wrong but more than likely the issue is related to the config you are using to get this setup. Check to make sure you are setting the URI.Host property to the domain. The library is not able to figure out your domain name by default as the script could run as a cron task or something else. Your server is just an IP address remember. The library won't have access to the DNS info and even if it did, you could have multiple domains pointing at the one server IP. By providing the library with the domain name, it will know that this is the host and will not add a nofollow attribute to any links for this domain.

$config = HTMLPurifier_Config::createDefault(); 
$config->set("URI.Host", "mydomain.com"); 
$config->set('HTML.Nofollow', true); 
$config->set('HTML.SafeIframe', true); 
$config->set('Attr.EnableID', true);

 

Related Questions

Convert Json To Xml

Bitrate Converter

GUID Generator

GUID Validator

Convert Json To C# Class

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.