How to Install a 301 Redirect?

0
164

The 301 Permalink Redirect” is the most effective and friendly for search engines a method to redirect Web sites. It can be used in different situations, including:

  • Redirect the old site to the new address
  • to create multiple domains pointing to one site
  • to ensure only one version of their site (with www or without www)
  • to synchronize the changes in the structure of the URL

There are several ways to install 301 redirection. Let’s look at the most commonly used of them:

PHP redirection of static pages

in order to redirect the static pages to a new address, simply insert this code inside the file index.php.

<?php
header("HTTP/1.1 301 Moved Permanently"); the
header("Location: http://www.newdomain.com/page.html");
exit();
?>

PHP Canonical

Canonical Redirection redirection of add or delete the www. Prefixes for all pages within the domain. The code below will redirect visitors from the domain.com www.domain.com.

<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently'); the
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>

Apache .htaccess redirects the Static Pages

In order to apply this method, you need to add code in the .htaccess file. If there is no file, create it and put in the root directory of your site. The code can be added by using a plain text editor.

Redirect 301 /old/oldpage.htm
/new Http://www.domain.com/newpage.htm/

Apache .htaccess file, the canonical Redirect

This method is similar to that described above. Changes to the code that will redirect visitors from domain.com to www.domain.com

Options FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

LEAVE A REPLY

Please enter your comment!
Please enter your name here