To automatically redirect visitors

When changing the domain or URL of an article, due to backlinks and indexing in search engines, visitors have to be redirected to a new address. There are several ways.
Note that only 301 redirects that require .htaccess or PHP are valid for search engines.

Using .htaccess (Apache Server)

The. " Htaccess" file at the root of the site (or in the subdirectory, if it concerns its content) will be taken into account by search engines. It will contain a string according to the format :

RewriteEngine on
redirect 301 /répertoire/fichier site-web/répertoire/fichier


Example:

RewriteEngine on
redirect 301 /mapage.html http://www.example.com/autrepage.html  

To redirect the entire site to the site root and destination, for example:

RewriteEngine on
redirect 301 /  http://www.example.com/

or:

RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/ [R=301]

If your account has a "www" directory, .htaccess is placed in "www" and can still be placed in subdirectories with settings specific to them.
The file must be in Unix format.

Use of frames

If the server (for example, a Windows server) does not recognize. "Htaccess" or the "redirect" command, the framework allows you to automatically redirect the user. The index.html file contains the following lines instead of the "body" tag:

<frameset rows="*,0" cols="*" border="0">
  <frame src="http://www.example.com" name="mapage" border="0"
     frameborder="NO" RESIZE scrolling="no">
  <frame src=""> 
</frameset> 

Note that the site name displayed in the browser URL field will always remain the address entered by the user.

Using JavaScript

<script language="JavaScript"> 
    this.location="http://www.example.com/index.html";      
</script>
<noscript> <a href="http://www.example.com/index.html">Nouvelle URL</a> </noscript>

This only works if JavaScript is not disabled. The code is placed in front of the "body" section, which may contain a link to a new page on which the Internet user will click when JavaScript is disabled in his browser.

Using PHP

If the page has a PHP extension and is therefore processed by the interpreter, you can replace the old page with a redirect:

<?php 
   header("Status: 301 Moved Permanently"); 
   header("Location:http://www.example.com/mapage.php"); 
?>

The URL of the new page.

See also...