Jeremy Scharlack's Blog
(not | yet) another blog
Tech
Archives

« New Comments | Main | Neocons »

February 04, 2004

Changing URLs in comment body

I also changed the urls posted in comments to prevent spammers from increasing their google ranking. Now all urls posted of the form <a href=”http://www.wherever.com”> will be changed to <a href=”http://blog.scharlack.com/go.cgi?link=www.wherever.com”>, using the perl script I described previously.

The change is simple enough for anyone who knows perl. This regular expression will do it:


s/http:\/\//http:\/\/blog.scharlack.com\/go.cgi?link=/g

Not too bad for a regex, but still weird looking. It simply substitutes all instances of “http://” with “http://blog.scharlack.com/go.cgi?link=”. It does it globally hence the /g. The backslashes are placed before any slashes to “escape” them since / means something to a perl regex.

Now to put regex ability into movable type. For that I got Brad Choate’s plugin mt-regex.

There are manyways to use mt-regex, but I just needed to do a simple substitution in the comment body. To do that i just changed the MTCommentBody tag to:

<$MTCommentBody regex="s/http:\/\//http:\/\/blog.scharlack.com\/go.cgi?link=/g" $>

Posted by Jeremy at 02:26 AM | Link | TrackBack (0)


Comments
Post a comment









Remember personal info?






 

Archives

Recent Entries

Links




Powered by
Movable Type 2.63