Guys, Guess i've been penalized on a site for too much outbound links... and i need to solve this as soon as possible to get my rankings back. Gotta turn NoFollow lots of links in 500 different HTML pages... I'm in trouble Is there any Php script or similar that turn all links NoFollow on a html site? Any help appreciated guys!
You might want to get a copy of Macromedia Dreamweaver. It has a really good find/replace function that you can use on one file, all open files or even all files within a certain directory. You could first replace every occurrence of '<a href=' with '<a rel="nofollow" href='. Then do a second find/replace to remove all of the nofollows that were just added to your internal links. Something like replace '<a rel="nofollow" href="http://www.domain.com' where the link starts with your domain. If you use relative links it would be a bit more complicated. If that's not sufficient you might have to custom program a php script to do something similar.
s/<a href/<a rel="nofollow" href/ this is a regex, if you have access to *nix then you can use this + sed to accomplish what you need....just make sure to backup your files first! edit: that should read s/<a href/<a rel="nofollow" href/g Code (markup):
sed is a linux/unix command line utility for editing files. you can also use gsed if it is available. from within a directory sed 's/<a href/<a rel="nofollow" href/g' *.html Code (markup): this command will substitute (that's the s in the beginning) all instances of <a href Code (markup): with <a rel="nofollow" href Code (markup): for every file that ends in .html in the directory (same as manually opening each one and doing a find/replace...only it is one one-line command per directory aka "adding the nofollow attribute to all links in all files in a directory" There is also a switch to make it recursive (all directories from within that directory) but it doesn't work with all versions of sed *ie: solaris 9
amerigohosting, thanks for you feedback but frankly I am lost here. How can i insert the command? sed 's/<a href/<a rel="nofollow" href/g' *.html Code (markup):
Here is a function for PHP to turn a link into no follow.... function filterHref ($str) { $str = stripslashes($str); $preg = "/<[\s]*a[\s]*href=[\s]*[\"\']?([\w.-]*)[\"\']?[^>]*>(.*?)<\/a>/i"; preg_match_all($preg, $str, $match); foreach ($match[1] as $key=>$val) { $pattern[] = '/'.preg_quote($match[0][$key],'/').'/'; $replace[] = "<a href='$val' rel='nofollow'>{$match[2][$key]}</a>"; } return preg_replace($pattern, $replace, $str); } PHP: Here is an example of implimentation... <?php function filterHref ($str) { $str = stripslashes($str); $preg = "/<[\s]*a[\s]*href=[\s]*[\"\']?([\w.-]*)[\"\']?[^>]*>(.*?)<\/a>/i"; preg_match_all($preg, $str, $match); foreach ($match[1] as $key=>$val) { $pattern[] = '/'.preg_quote($match[0][$key],'/').'/'; $replace[] = "<a href='$val' rel='nofollow'>{$match[2][$key]}</a>"; } return preg_replace($pattern, $replace, $str); } $text1 = '<a href="http://www.google.com">Google</a>'; $text2 = '<a href="http://www.google.com">Google</a>'; echo $text1; echo '<br />'; echo filterHref($text2); ?> PHP: Ive tested it and it works fine