Access Keys:
Skip to content (Access Key - 0)
My Area (Access Key - 2)

Toggle Sidebar
Your Rating: Results: PatheticBadOKGoodOutstanding! 20 rates
elympics elympics Delete
sfx sfx Delete
voyager voyager Delete
aleph aleph Delete
primo primo Delete
metalib metalib Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

TRUNC - URL Truncator (tinyurl)

Tags: , , , , ,
Last Updated: Feb 19, 2010 17:24

  • Description

    TRUNC is a URL truncator application, a system that uses a small URL alias to redirect to another URL - typically one that is very long. It comes packages with a web services based api that can be plugged into any Ex Libris product using Javascript, allowing a site to offer tidy URLs that go directly to pages with longer URLs, for example, OpenURLs.

  • Author: Mark Dehmlow
  • Additional author(s):
  • Institution: University of Notre Dame
  • Year: 2010
  • License: GNU GPL version 3, Copyright 2010 University of Notre Dame/Hesburgh Libraries
  • Link to terms:
  • Skill required for using this code:

Security (READ)

TRUNC uses a technique called URL redirection - it essentially creates small URLs that are aliases, these aliases redirect to the longer URLs. If used properly, these can be an effective means to provide succinct URLs to systems like SFX and Aleph that have very long URL structures. If used improperly, this technique can mask a URL that your users should not go to, exposing them potentially to malicious computer attacks, viruses, etc.

The benefit to installing TRUNC locally is that you give your small URLs your local branding instead of using a service like tinyurl, and if implemented properly, you can establish trust with this service for your users. The key to making sure TRUNC is used properly is to limit who can create truncated URLs. It is highly recommended that you lock down the trunc/admin directory to be accessible by only specific servers that you designate or password protect it to create an audit trail - the database is able to track IP address and username if sent to it via the api. Here is a sample directive to place in an .htaccess file in the trunc/admin directory:

This will allow access to the index.php (manual creation script) and api.php (api script) only from machines that have a hostname ending in or with the IP address You can add other directives that will force login as well or use some combination of IP or username and password.



Programming language

perl (available on request)

Software requirements

php distribution

php 5 or greater with mysql, dom, and SimpleXML modules loaded
Apache (optional)

Screen captures


Working example

Using the following Ex Libris open interfaces


Version 1.0

Release notes

Initial release of TRUNC. I will create a linked article for how to integrate into SFX.

Installation instructions

php distribution

After downloading the application package, you will need to create a database schema in mysql. You will also have to create a mysql user account that has DROP, CREATE, INSERT, and SELECT permissions. Once installation is complete, you can remove DROP and CREATE from the account, they are only for installing the database.

You can unzip and untar the package and drag and drop it to a web space if you have that ability. Otherwise, place it on your web server and run the following from the command line:

Next go into the trunc/admin directory and edit the config.xml file.

Configuration File:

baseUrl is the URL base that your truncated URLs will use, e.g.
apiUrl is the URL that the system will use to send URLs to and get back truncated URLs, they system has a web entry form that uses the api to create truncated URLs
the database section holds all of your mysql connection details
urlCodeLength is the length of the truncated code, e.g. l3nfo in
note: the system by default will not allow codes shorter than 5 characters

Next, navigate a web browser to the ../trunc/admin/install.php
This script will walk you through the installation, let you know what isn't in place, and once you have all of the php modules installed and database configuration details, it will install the database for you.
Once installation is completed properly, you will be redirected to the small url creation form ../trunc/admin/index.php

Optional Apache Configuration

If you would like your truncated URLs to look like instead of, you will need to configure your Apache environment to do this for you.

First you will need to allow directives to be placed in .htaccess files - these are files that can apply directives at the directory level.

For security, make sure you have this directive which prohibits people from looking at your .htaccess files

.htaccess files

To have pretty truncated URLs without the script name in them, e.g.
You must have these two lines in the .htaccess file in the trunc directory

This performs URL rewriting which treats every URL of the form as if it is going to

Optional Additions

You may also wish to set index.php or index.cgi to be a valid index page (that is one you can see by only typing in the URL to the directory - e.g.

If you are using the CGI version, you will need to allow CGI for the directory you put it in, if you aren't using the cgi-bin directory

If you are using the CGI version, you may also need to add a line to your config that specifies how to handle cgi files

Known issues



Page Attachments

File NameCommentSizeNumber of Downloads
trunc_php.tar.gzTRUNC Application Package for php182 kB247
trunc.tar.gzTRUNC Application Package182 kB141
use.jpguse105 kB4975
installation2.jpginstallation299 kB1449
installation.jpginstallation1106 kB1447

Added by Mark Dehmlow on Jan 28, 2010 22:40, last edited by Mark Dehmlow on Feb 19, 2010 17:24

Adaptavist Theme Builder Powered by Atlassian Confluence