Desktop and Server Virtualisation Specialist 

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)8456 446 800 / +44 (0)1223 359900
E: enquiries@precedence.co.uk
Home right arrow Support right arrow Internet Services right arrow Directoryredirect

Using .htaccess files to redirect one directory to another

At Precedence Internet, we use a webserver called Apache. This is most widely used webserver in the world. Apache is highly configurable and it is possible for some options to be set by the end user. This is performed by creating text file called .htaccess in your directories.

A brief guide is given below, but this is no substitute for having read the Apache documentation.

Redirecting one directory to another

If you have restructured your website and moved pages into different directories, you may still get accesses to your old pages if they are referenced from search engines. It is often useful to redirect accesses to your old URLs to new ones. A simple method is to put a Refresh in your HTML source. For example,
<META HTTP-EQUIV=refresh CONTENT="10; URL=/newpages/index.html">
 
The following will redirect accesses to your page to /newpages/index.html after 10 seconds.

PHP users can use:

<?php
  header("Location: /newpages/index.html");
?>

Unforunately, a simple Refresh or Location is of little use if you wish to redirect all accesses to a directory structure to a different site or directory as you would not be able to redirect graphics and would need to keep your old directory full of all the possible pages.

To redirect a whole directory tree, simply create a text file called .htaccess in the directory containing a line similar to the following:

Redirect /oldpages http://www.yoursite.com/newpages
N.B. URLs and paths given should not end in slashes
N.B.2 The destination page must be given as a complete URL with http:// at the start.

The above example would redirect http://www.yoursite.com/oldpages/sales/information.html to http://www.yoursite.com/newpages/sales/information.html

© Copyright Precedence Technologies 1999-2024
Time elapsed:0.018