Pages moved, inform the user but don’t tell

Actually, on my web site, a number of pages have been moved around in the last year. Additionally, some pages are now located so deeply in the site structure that access paths are quite convoluted.

The solution seems to go through the use of server page redirection. In Apache (the web server is based upon), this goes through the writing of one or more .htacess files. Let’s see how this is done.

We must first give a first idea of what this little inconspicuous file does. Surprisingly, in a single location, it provides a large number of services (including authentication, for example), and it allows us to easily redirect from one address to another.

Here is a page giving details and examples about .htaccess redirection.

The advantage is that with a few instructions, it is possible to hide complexity from the user.

Redirection of one page

I had several pages initially located at the top of the directory structure in my web site. This was convenient when there were not a lot of files. Today, there are thousands of them and this would be utter madness to keep most of the files at the top. However, many people keep the old paths and some search engines have been used to these locations. The solution: Move files in their own directory and add a redirection.

Example: shareware files (pages describing my old software business – using the shareware model).

The code I used (in the /.htaccess file):

Redirect 301 /ygrep.htm
Redirect 301 /bitlist.htm
Redirect 301 /clusterv.htm

Redirection of a full directory

I wanted to simplify the path to access to the WordPress pages (they have a quite long path down to the details like and if I could reduce it to it would already be an improvement.

The code I used (in the /.htaccess file):

Redirect 301 /fr

I also wanted to move a bunch of files from one place to another (while introducing a full translation from English to French). But there was already a very significant traffic jumping directly to these pages (from search engines, from direct use in several blogs, from other friendly web sites).

The code I used (in the /.htaccess file):

RedirectMatch 301 /photo/(.*)\.htm$$1.php

Additional advice

Remember that your Apache web server needs to be able to access this file internally. The usual advice is to set rights with the command:

chmod 664 .htaccess

Since the web server always looks in several places before deciding what to do with the redirection task, it is advisable to group all the redirection orders in a single location (the .htaccess file in the root directory of the web site). This slightly reduces the work load on your web server and avoids you going all other the place when you need to change something.

Additionally, the syntax for .htacess in local directories becomes a little more confusing because of the use of relative paths and such.

One more bit of advice: .htaccess can be used to do authentication. However, this is slightly more unsecure than doing it directly in the server configuration (because the .htaccess may become world-readable while it has the passwords quite accessible even if not in plain form).

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.