Redirecting clients when websites change

Whilst looking at the website statistics for my main website, I realised that many users were attempting to access pages that no longer exist on the server. Some may argue that old content should be left in place, but others will disagree and my preferred approach is to redirect requests to the new locations, or at least to provide a polite message that the document has been removed and a link to the home page! Fortunately on an Apache server, this may easily be achieved using an .htaccess directive.

Various types of redirect are available through .htaccess, using the syntax:

Redirect [status] URL-path URL

The status argument can be used to return a number of HTTP status codes:

  • permanent returns a permanent redirect status (301) indicating that the resource has moved permanently.
  • temp returns a temporary redirect status (302). This is the default and is assumed if no status argument is given, indicating to the client that the resource has moved temporarily.
  • seeother returns a “See Other” status (303) indicating that the resource has been replaced.
  • gone returns a “Gone” status (410) indicating that the resource has been permanently removed. When this status is used the URL argument should be omitted.

Other status codes can be returned by giving the numeric status code as the value of status. If the status is between 300 and 399, the URL argument must be present, otherwise it must be omitted.

For example, a temporary redirection from old file or directory to new:

Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
Redirect /olddirectory http://yoursite.com/newdirectory/

or a permanent redirect:

Redirect permanent /olddirectory http://www.yoursite.com/

or redirect with error 410:

Redirect gone /oldfile.html

Full details for Apache users may be found in the Apache HTTP Server documentation.

Microsoft Internet Information Server (IIS) users can find information on redirecting requests to files directories or programs in the IIS 6.0 Operations Guide.

RFC 2616 details all HTTP status (including error) codes.

Changing the default documents for a website

My ISPs’ Apache servers are configured for index.html and index.htm to be the default documents; however since implementing server side includes in my websites I need index.shtml to be recognised as the default document.

Fortunately, this can be achieved using the following directive in the corresponding .htaccess file:

DirectoryIndex index.shtml index.html index.htm

Microsoft Internet Information Server (IIS) users can find information on setting up default documents in the IIS 6.0 Operations Guide.

Implementing custom error pages for a website

One of the features used in my website is custom error pages, which allow errors to be handled using a format that matches other documents on the site.

Apache users can configure custom error messages using .htaccess. Once pages have been created for an error message, include a directive in the .htaccess file as follows:

ErrorDocument error-code document

For example, ErrorDocument 404 /errors/404-notfound.shtml will redirect any page not found (HTTP error 404) errors to display the /errors/404-notfound.shtml document.

Full details for Apache users may be found in the Apache core features documentation.

Microsoft Internet Information Server (IIS) users can find information on configuring custom error messages in the IIS 6.0 Operations Guide.

RFC 2616 details all of all HTTP status (including error) codes.

Using server side includes in web pages

One of the features used in my website is server side includes (SSI). The SSI code allows my sites to include dynamic information which would otherwise require scripting that may not function correctly with certain browsers.

SSI is pretty simple. Apache users need to edit the .htaccess file in their web root directory to allow SSI, adding the following lines:

Options Includes
AddType text/html .shtml

AddHandler server-parsed .shtml

Some of these may not be necessary if they have been set at a higher level in the Apache configuration by the ISP or server administrator – for full details, see the Apache Tutorial: Introduction to Server Side Includes.

Microsoft Internet Information Server (IIS) users can find information on using server side include directives in the IIS 6.0 Operations Guide.

Once enabled, pages which call the server-based code should be named .shtml (or whatever file extension is defined in the configuration). Because my ISP has configured its servers for the default web page to be called index.htm or index.html, it was also necessary to change the default documents for the website.

One use of SSI to reuse common HTML code (e.g. headers, menus, etc.), but another useful application is to report document information (e.g. date last modified). There are many references on the Internet for SSI options, but one of the most useful is Craig McFetridge’s SSI page on the Carleton University website, with another being the one found on the ThinkQuest Amazing HTML website.

Using .htaccess to improve the user experience for a website running on an Apache server

A few weeks back, I updated two websites (which run on my ISPs’ Apache servers) to use various features which improve the experience for users of the site. These features include:

All of these features (and more) may be controlled on an Apache server using a file called .htaccess, which is intended for users who do not have access to the server configuration to make configuration changes on a per-directory basis.

In general, where access to the server configuration is available, then changes should be made at the server level; however in a hosted environment, .htaccess allows content providers to make their own configuration without affecting other users of the server.

Administrators should be made aware that enabling .htaccess on a server does incur a performance hit as Apache will look in every directory on the path for an .htaccess file, and will load the file, whether or not the directives contained within .htaccess are relevant to the HTTP request. For this reason, some ISPs may prohibit the use of .htaccess.

Microsoft Internet Information Server (IIS) does not have an equivalent to .htaccess and all configuration must be carried out using the various IIS administration tools (along with an appropriate organisational security model).

Links
Apache Tutorial: .htaccess files
Comprehensive guide to .htaccess

Passed Microsoft Certified Professional exam 70-224

Today I passed the Microsoft Certified Professional exam 70-224: Installing, configuring and administering Microsoft Exchange 2000 Server.

Microsoft’s non-disclosure agreement prevents me from saying too much about the exam but much to my relief I scored maximum points in three areas (“installing and upgrading Exchange 2000 Server”, “configuring Exchange 2000 Server” and “managing Exchange 2000 server growth”) – as someone who primarily designs and implements systems (rather than performing daily operational and administrative tasks) I would have hoped these would have been my strong areas!

It may seem odd taking an Exchange 2000 Server exam in 2004, but I booked this a year ago (whilst I was still working with Exchange 2000) and if I didn’t take it by tomorrow then I would have just lost my money! Perhaps I’ll get around to doing an Exchange Server 2003 exam soon, but I need to start working with the product again first…

Quality tips for webmasters

I’m no web site designer, but anyone who has seen my main website recently will have noticed that it is undergoing a few changes. I hope to extend the new style to my other websites soon (including this blog), but time is not on my side.

During my code validation with the W3C Markup Validation Service and the CSS Validation Service I came across the W3C’s Quality Tips for Webmasters. There is some useful stuff there to help novice (and experienced) developers to produce better websites. Worth a look.

Your e-mail: anytime, anyplace, anywhere

For some time now, I’ve been using the mail2web.com web service for reading my e-mail when I’m away from home.

The basic service doesn’t require registration (no details are stored as it is basically an HTTP wrapper for POP3 and IMAP4 servers), but registered users can use a customised mail2web site with multiple e-mail accounts, favourite newsgroups, frequently used links and even their own image.

Now the guys at mail2web have made the service even better, with WAP and PDA versions of the website. In an earlier post, I gave details for connecting a PDA to the Internet using the Vodafone GPRS service (the principle is the same whoever your mobile carrier). Now I can access my e-mail on a page that is formatted to suit the PDA screen.

Accessing the Internet using Vodafone GPRS and a PDA with Bluetooth

I’ve been trying to get my PDA (an HP iPAQ 2210) to connect to the Internet via a Bluetooth connection to my business mobile phone (a Nokia 6310i). I was having problems with this until I found the details on the Vodafone website (Get More from Your Mobile | Internet on the Move | Set up your PDA); however the Vodafone details don’t include PDAs running Windows Mobile for Pocket PC 2003 or Bluetooth connectivity and so I’ve posted my own instructions here:

(these notes assume that that you are familiar with using the PocketPC and that you have already successfully paired the PDA with the mobile handset).

From the Start menu, select, Settings:
Move to the Connections page and click the Connections icon, then select Add a new modem connection.

Give the connection a name (e.g. Vodafone GPRS) and select a Bluetooth Dialup Modem, before clicking Next:

Enter the number as *99# and click Next:

Enter the username and password (both web). Leave the domain name empty and click Advanced…:

On the General page, set the Baud rate to 57600 and enter a modem command string of +cgdcont=1,"ip","Internet":

On the Port Settings page, set 8 data bits, no parity, 2 stop bits and hardware flow control:

All other advanced settings should be default (most notably the connection should use server-assigned [IP] addresses):

Click OK, and then Finish.

Turn Bluetooth on:

Launch the Vodafone GPRS connection (e.g. by clicking the connectivity icon at the top of the screen and then clicking *99#):

The PDA will initiate the connection with the mobile handset (it may be necessary to confirm the connection on the handset):

Once connected, Internet services can be accessed as normal:

To disconnect, click the connectivity icon at the top of the screen and click Disconnect:

Finally, turn Bluetooth off to conserve power: