6th January 2009

Using mod_rewrite to prevent hotlinking

Monday, May 12th, 2008

Hotlinking is the practice of linking to an object (generally an image file) from one site (the donor site) onto another (the linking site). We’re frequently asked by our hosting clients if there is a way to stop people doing this as it’s consuming their bandwidth or server resources. This is easily done with the mod_rewrite rules below.


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?opensourcery.co.uk/.*$ [NC]
RewriteRule \.(gif|png|jpe?g|$ - [F]

This will deny requests for any .gif, .png, .jpg or .jpeg file unless the referrer is either www.opensourcery.co.uk or opensourcery.co.uk.

You can substitute the last line for the one below if you wish to redirect people to an alternative image rather than simply denying the requests.

#RewriteRule \.(gif|png|jpe?g|$ img/dontsteal.gif [L,NC]

It’s worth remembering that the referrer header is optional so although almost every modern browser sends this with each request it’s possible that some won’t do meaning these rewrite rules may result in broken images for some users of your site.

Scheduled maintenance with mod_rewrite

Sunday, April 13th, 2008

A public sector customer recently had a requirement to redirect visitors to one of their applications to a holding page overnight while the company who support the application carried out some maintenance work. The work was being carried out between 1am and 7am to minimize disruption to the members of public who use the application.

Keen to help, but also to get a good nights sleep we looked to mod_rewrite to provide a solution (we manage the front end servers, which run Apache).

We added the following lines to our httpd.conf to redirect any traffic to the site to a holding page at /static/offline.php from 00:55 until 07:30 to a holding page:

RewriteEngine on
RewriteCond %{TIME} >20080407055000
RewriteCond %{TIME} <20080407073000
RewriteRule !^/static/offline.php$ /static/offline.php [PT,NS]

Alias /static "/var/www/www.example.com/static"

As the application sits on a Tomcat instance behind mod_proxy, we also added the following line to prevent mod_proxy from handling requests for the /static directory.

ProxyPass /static !

We created the offline.php file, including with the line below to ensure that search engines didn’t index the holding page.

header("HTTP/1.1 503 Service Temporarily Unavailable")

New website

Sunday, April 6th, 2008

Our new website is now online.

As you would expect, the site is created wholly using Open Source software. It has been created using the excellent WordPress software and is
hosted on our own LAMP (Linux/Apache/MySQL/PHP) servers.

Support for Open Source software

Sunday, April 6th, 2008

We can provide remote or onsite support for Open Source operating systems (Linux / BSD) and applications such as the Apache webserver, Tomcat, MySQL. There are more examples of products we’ve worked on our experience page.

We’re comfortable working in mixed environments too, for example running Apache, MySQL and PHP on Windows (commonly known as the WAMP application stack)

Our experience

Sunday, April 6th, 2008

We have been working with Free and Open Source Software since 1998 and have worked with wide variety of customers, ranging in size from single employees through to large multinationals. An increasing amount of our work is with SME’s who are making use of Open Source software to reduce their IT costs. Our customers are in both the private and public sectors.

Free and Open Source software we work with

Our preferred Linux distributions are Debian, Ubuntu and Red Hat Enterprise Linux, but we have considerable experience with a wide range of Linux distributions. We are also experienced with BSD, in particular OpenBSD and FreeBSD.

We build mail servers based around either Exim, Postfix or Sendmail MTA’s and generally use Courier IMAP/POP3 server. We also utilise a number of open source anti-spam packages including SpamAssassin and amavis.

A lot of our work is building and supporting the infrastructure for web facing applications and websites. Generally this involves Apache HTTPd as the web server, with either a TomCat application server or PHP application. Generally these make use of a database such as MySQL or PostgreSQL. The most common configuration we work with now is known as the LAMP stack (Linux, Apache, MySQL, PHP). We’ve also made use of squid as a web content accelerator, and a caching proxy server.

We have setup and provided support for numerous Open Source web applications such as MediaWiki, Drupal, Blojsum and Wordpress (which we use to run this site).

We use Samba to allow customers to run Windows compatible file/print server without needing to run Windows.

We also work with a number of monitoring packages, and make extensive use of packages such as monit and smokeping as well as our own custom monitoring scripts to monitor our customers systems and networks.

These are just examples of our work, so if you have another Open Source system you’d like us to support then please contact us.