Leaving a Forwarding Trail with a Permanent Redirect

Permanent redirects can be very useful when removing a page from your site or renaming a page. There have been many solutions to preventing your users from seeing a “Not Found” error. There are many times when it’s necessary to remove a page or change it’s name. This will normally cause problems if you don’t take precautions.

There are many ways to handle this problem and most of them will entail leaving a file on your server that has the filename of your old file. This file will usually have some kind of code in it to transfer the user to the new page or to a relevant page. No matter what language you use, site management starts to become a problem if you have too many of these floating around your site.

Is there a better way you may ask. Of course! At Truecast there always is. Ok most of the time there is or if there isn’t, we’ll find one. So what is the solution to your orphaned file woes? The .htaccess file again. For those of us fortunate enough to have a Unix/Apache web server, there is a better way. Visit Redirects and Other Timed Responses for more information on why a permanent redirect is the best solution.

Permanent redirects (error 301) are a way to telling the web server directly that a page is no longer available at an address and can now be found elsewhere. The good thing is that it doesn’t need the old file around to do it’s trick. And it’s very easy to do for those of you that are web challenged.

The hard part of this is finding and making sure you have an .htaccess file in the top level of your web directory. I will write an article later about how to create one or find it on your site.

An any case, download it from your site and edit it in your favorite text editor. For each redirect that you want to make, type or paste in this line of code and edit the urls in it.

redirectpermanent /file.html http://www.yourdomain.com/newfile.html

After you are finished, save the file and upload it back to the server. Try and access the page you just redirected and it should now auto take you to the new address. That’s it, your done. You can keeping adding new forwards to your site by adding them to that file and you can delete the old files from your server.

Written January, 2005 © Truecast Design Studio. Author: Daniel N. Baldwin.