System Tools

Web page automatic redirection

Why to use an automatic redirection for a web page ?

  • The internal structure of your website has changed and you want your old links to be redirected automatically to the others. So indexed pages on search engines and favorites bookmarked by your visitors will still work.
  • You want to redirect all 404 errors to a customized web page.
  • To optimize your ranking on search engines.
  • To inform visitors of a specific web site that all information are now transferred to a new URL.
  • In order to offer a web page that refresh itself automatically on a regular basis.
  • To display a slideshow where pictures are scrolling without any programming.

Automatic redirection through HTML or Java Script

In both cases you should insert your code between the two <HEAD> </HEAD> tags at the top of your HTML page.
These two methods allow you to make an immediate rerouting (transparent for the visitor) or after a defined deadline.

Redirection in an HTML page using META TAGS

<meta http-equiv="refresh" content="5; URL=">
Here, this simple META tag will redirect the browser to the specified URL after 5 seconds.
This method is fully compatible will all Internet browsers and allow you to be sure this redirection will be effective, even if Javascript is disabled.

Redirection in an HTML page using JavaScript

<script language="javascript" type="text/javascript">
  window.setTimeout('window.location=""; ',5000);
// -->
This code should be inserted in the page header and make the browser open the new URL ather 5 seconds (5000 milliseconds) 

<script language="javascript">
You can also use the location.replace function which will "replace" the actual address by the new one. This is very interesting to avoid a visitor opening again the redirection page if he use the "back" button of the browser to see the previous page.

Complete example of an HTML file that will make an automatic redirection

<HEAD> <TITLE>Sample Page</title> <meta http-equiv="refresh" content="5; URL="> </HEAD> <BODY> If your browser doesn't automatically redirect you, use that link <a href="">Webmastips Website</a> </BODY> </HTML>
In that example you can notice that it's very easy to implement that type of redirection.It's even recommended to add a note in the page that include a link where the user can click if the automatic redirection is not working properly. 

Automatic redirection using an Apache .htaccess file

It's possible to create an automatic redirection directly with Apache.
Redirect /old_subdir/index.html /new_subdir/index.html
Redirect /subdir/index.html
You just have to place an .htaccess file in the source directory and append as many lines as you need. the command is quite simple : the line should begin with Redirect, then you have to specify the old URL (source) with a relative path (depending of the .htaccess file position in your system file. At the end of the line, indicate the destination URL with a relative path if the destination is in the same system file or with an absolute path using http:// to start your URL, if it's an external link. 

Select your language :