Main Content
How to set up short and meaningfull alternative URLs Archive - Originally posted on "The Horse's Mouth" - 2010-10-02 11:54:51 - Graham Ellis
Wouldn't it be nice is URLs were shorter? Well - there are ways of making them shorter these days and you'll find them on networking sites like Twitter ... http://bit.ly/d7t8ID or http://bbc.in/XTQ8V . But where such URLs gain in brevity, they loose in comprehensibility.
But it's very easy to provide brief URLs that *are* meaningful too - and to do so on your own site if you have a short domain name (not www.whydidiregistersomethingthislong.co.uk) - we've done it, and let me show you how.
I wanted a quick link to our hotel booking page at https://lightning.he.net/~wellho/hotel/reservation.php - I wanted to go there from wellho.info/booking (yes, do try that link - it will work!).
Here's how I did it:
1. On the server for the domain that's got the short URL, I added the following to the .htaccess file in the DocumentRoot (the server's running Apache httpd with mod_rewrite and AllowOverrides On)
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ http://www.wellho.net/short/ [L]
That redirects any URLs in the root directory that are just strings of letters and digits to a more structured directory at a longer URL within our main domain.
2. In the "short" directory on the main domain server, I've also got a rewrite line which sends the received name to a PHP script (requirements on this machine - httpd, mod_rewrite, Overrides allowed and PHP):
RewriteRule ^([a-zA-Z0-9]+)$ divert.php?shrtfrm=&%{QUERY_STRING}
3. The PHP script looks up the code in $_REQUEST[shrtfrm] from a file or database, and sends out Location header telling the browser where to go:
header("Location: $fn");
And it is nice! .... I have a whole lot of meaningful short links I can give to people, and I can use them as a switchboard too - so that if we come up with a new map there isn't a huge amount of extra work to do to tell people where it is.
Let's see if you can guess what you'll get if you follow the following links (which will open in a new window):
wellho.info/weather
wellho.info/map
wellho.info/course
wellho.info/coursebooking
wellho.info/hotel
wellho.info/hotelbooking
wellho.info/askus
wellho.info/coffeeshop
wellho.info/chamber
wellho.info/carnival
I'll confess to having done a bit more too ... . If you put in a number, it will take you straight to that article number in "The Horse's Mouth", and if you put in a word that happens to be the name of a page on our wiki, it'll take you to a page there.
wellho.info/2202
wellho.info/2894
wellho.info/727
wellho.info/beanacre
wellho.info/coatewater
wellho.info/westwoods
wellho.info/phonein
wellho.info/walkin
And - yes - if you enter something that's not on our site you'll get an index of all the special links:
wellho.info/alpaca
The images used to illustrate this article all come from pages that are short-linked above. Can you find them?
Some other articles
H312 - Tips and Techniques The power of scripting FileMaker Day to Unix Time conversion PHP - some quick fixes if scripts have issues, and how to use our support Problem ... I want to print a series of numbered forms A comment on comments in PHP This article How did I do THAT? PHP preg functions - examples and comparision Injection Attack if register_globals in on - PHP Keeping PHP code in database and running it PHP - Parse error: syntax error, unexpected $end ... Two PHP include files to make easy web site indexing and navigation Checking server performance for PHP generated pages Easy conversion - image formats, currencies and distances PHP Standalone - keyboard to screen Dates, times, clickable diarys in PHP Syntax checking in PHP Hot answers in PHP H305 - Web server configuration On time This article PHP - Object Oriented Design in use Dynamically watching your web site via a PHP wrapper How did I do THAT? Predictive Load Balancing - PHP and / or Java Pointing all the web pages in a directory at a database G902 - Web site techniques, utility and visibility Almost so wrong, but perhaps it's right for some? Effect on external factors on traffic to our web sites - an update Selecting RECENT and POPULAR news and trends for your web site users Well House Consultants, Well House Manor, First Great Western Coffee shop, TransWilts / 2014 web site reports Facebook marketing - early experiences How do I post automatically from a PHP script to my Twitter account? More or less back - what happened to our server the other day Web site - fully back! Helping search engines with appropriate 400 error codes TV show appearance - how does it effect your web site? An email marathon Some traps it's so easy to fall into in designing your web site Legal change - You need to obtain user consent if you use cookies on your website Short Web Addresses for Melksham QR codes with marketing logos embedded Some TestWise examples - helping use Ruby code to check your web site operation Promoting a single one of your domains on the search engines How big is a web page these days? Does the size of your pages matter? Learning more about our web site - and learning how to learn about yours Sharing the user experience - designing a form with the customer in mind Who is knocking at your web site door? Are you well set up to deal with allcomers? Automed web site testing scripted in Ruby using watir-webdriver Google +1 - what is it? Finding and diverting image requests from rogue domains Looking back at www.wellho.net Making the most of critical emails - reading behind the scene Retaining web site visitors - reducing the one page wonders This article Is it worth it? How to run a successful online poll / petition / survey / consultation Web site traffic - real users, or just noise? Analysing Google arrivals by country of origin Status Page / breaks of service in early December Removal of technical resources from this site Writing with our customers words Koulutus, Open Source tietokone kielillä ldning, Open Source dator sprÃ¥k ldning, Open Source dator sprÃ¥k Opplæring, Open Source datamaskinen sprÃ¥k Uddannelse, Open Source computer sprog Opleiding, Open Source computertalen Formação, Open Source computador lÃnguas Ausbildung, die Open-Source-Sprachen Formazione, Open Source computer lingue Formación, de los lenguajes de código abierto Formation, des langages Open Source How important is a front page ranking on a search engine? Static mirroring through HTTrack, wget and others Web Site Loading - experiences and some solutions shared Cooking bodies and URLs Plagarism - who is copying my pages? Making our things easier to find How to avoid duplicating web page maintainance Find the link A few of my favourite things Web Bloopers - good form design - avoiding pitfalls I have been working hard but I do not expect you noticed Which country does a search engine think you are located in? Ever had One of THOSE mornings? Who is watching you? Rapid growth leads to server move How do Google Ads work? Kiss and Book To provide external links, or not? PHP course dot co, dot uk Online hotel reservations - Melksham, Wiltshire (near Bath) Colour, Composition or Content Where in the world / country is my visitor from? Perl, PHP or Python? No - Perl AND PHP AND Python! Ongoing Image Copyright Issues, PHP and MySQL solutions Script to present commonly used images - PHP A time to update pictures Above the fold with First Great Western Stuffing content into a web page - easy maintainance What proportion of our web traffic is robots? What brought YOU to our web site? Simple but effective use of mod_rewrite (Apache httpd) From Web to Web 2 Two new pages / sites Finding resources - some pointers Sorting out for a site map Drawing dynamic graphs in PHP Above the fold Our search engine placement is dropping. Search engine placement - long term strategy and success Training on Cascading Style Sheets Santa at the station Driving customers away Visibility Effective web campaign? Finding the language preference of a web site visitor Horse and Python training Where is a web site visitor browsing from Protecting images from theft Mirroring a dynamic site Keeping the visitors happy and browsing Denial of Service ''attack'' Bigger Box Campaign Getting favicon to work - avoiding common pitfalls Dynamic Web presence - next generation web site New Navigation Aid - Launch of My Wellho Form Madness What brings people to my web site? CMS - the minefield of Choices Graveyard pages Frightening and from-friend viruses and spams More maps Ordnance Survey - using a 'Get a map' What language is this written in? Growth pains Colour blindness for web developers The Iconish language Cover all the options An apology to Mr Boneparte Our most popular resources Information request forms, cleaning up spam Putting a form online Responding to spam Who are all these visitors? Searching for numbers Allow for peak traffic on your web site Your personal Google ranking The hunt for unique words Data Mining Implementing an effective site search engine Colour for access A case of case URLs - a service and not a hurdle No more 'Error 404' pages. Something better. Web design platoon Skills and responsibilities A607 - Apache httpd mod_rewrite Forwarding a whole domain, except for a few directories - Apache http server Adding a passcode to a directory Telling which ServerAlias your visitor used - useful during merging domains Simplest ever proxy configuration? Finding and diverting image requests from rogue domains This article Redirecting a page - silent, temporary or permanent? Dynamically watching your web site via a PHP wrapper Carrying a long URL around - looking for memorable shorts Redirecting a home page using mod_rewrite Bookkeeping If you have a spelling mistake in your URL / page name mod_rewrite for newcomers Pointing all the web pages in a directory at a database More HowTo diagrams - MySQL, Tomcat and Java Apache httpd, MySQL, PHP - installation procedure What to do if the Home Page is missing Using a MySQL database to control mod_rewrite via PHP Choosing between mod_proxy and mod_rewrite Simple but effective use of mod_rewrite (Apache httpd) Passing GET parameters through Apache mod_rewrite Apache httpd and Apache Tomcat together tips Clustering, load balancing, mod_rewrite and mod_proxy Using different URLs to navigate around a single script Apache httpd to Tomcat - jk v proxy