Backlinks for Movable Type

Here’s a challenge: You don’t have access to your website log files and you don’t have MySql. You still want linkback information to your weblog, just like everyone else. I faced this challenge yesterday. Read on for the results…

Since I have some experience on Perl, making linkback program proved to be rather easy. And because web is about sharing, I made the program and documentation available here.

Disclaimer: You’ll need some previous experience on two things: installing cgi programs on your site and editing templates. As always, it’s on your own responsibility if you break anything. Always make backups.

Security notice: The program is secure as far as I know, but I give no warranties.

Requirements: Perl (any reasonably new version should be enough) and a web server with exec server side include command enabled (check with your ISP).

Making linkback list for Movable Type

First, download refs.txt to your server. Rename it as refs.cgi and put it where you put other cgi scripts.

Configure script

Open the refs.cgi in your editor. In the beginning of the file, you’ll find some configuration options that you need to edit.

First, check out the path to Perl interpreter in the first line. Change it if needed.

Second, change variable file to point to an absolute path where you want to keep your referral log. It’s a good idea to keep it somewhere outside of the public_html directory.

Next, change variable mydomain so that it contains your weblog’s address. If you have longer address (eg., type in the address but leave out the www and filename (eg. $mydomain="“).

If you want to list referrals where the users used bookmarks or typed in the address for your weblog, set exclude to 0 and change dirlink text to your liking. It’s in Finnish now :-)

All other configuration options have default values that you can change if you want to.

Set up files

Check that you have set the proper permissions for the refs.cgi. The web server needs to be able to execute the script.

Create the referrer log. On Unix you can use touch command: touch /path/to/your/reflog. Use the same path that you wrote in your configuration file. On other servers, just create an empty file and save it. Make sure that the web server has read/write access to this file.

Modify templates

After that you’re ready to go live. Open your front page template (either in Movable Type admin view, or if you linked the template to a file, using your favourite editor). Find the place where you want to put the linkback log. Put following command on that place:

<!--#exec cgi="/path/to/cgi/refs.cgi"-->

Change the path so that it points to the place where you set up the refs.cgi.

In Pinseri, I added it to the right-side column this way:

<div class="sidetitle">
<div class="side">
Viimeisen 24 tunnin aikana Pinserin etusivulle on tultu mm. nist osoitteista...
<!--#exec cgi="/refs.cgi"-->

Go live with the referral list

Now save the template and rebuild your weblog. When you go to your site, at first you don’t see anything in your linkback log, because there are no referrals yet (unless your site is very popular). You can either wait for a while or go and make some referrals yourself. Go to a site that has a link to your weblog and follow that link. Now you have your first referral!

If you cannot see any backlinks, check that your weblog’s front page is set up to support SSI commands. You might need to set the execute bit for file index.html, or rename it to index.shtml in MT’s Template settings (go to Templates, select Main Index and change Output File to index.shtml; then rebuild and delete index.html file from the website).

Tidy up the list

As you can see, the referral links show the URL of referring page. If you got many backlinks from the friends’ pages, you might want to change the URL’s into something more informative. You can add name filters to the end of the refs.cgi – there are already couple of filters that you can use as an example. The format is:

elsif ($url=~m[regexp]) {

Change regexp to a regular expression that matches the address, and text to text you want to show instead of the address. Add new filters under old ones. Note that in the first filter, the command elsif has to be written as if.

That’s it!

As it says in the file, the program can be distributed freely, but I’d appreciate a link to If you make changes and improvements to the software, please send me a copy!


Leave a Reply

Your email address will not be published. Required fields are marked *