The “301 Permanent Redirect” is the most efficient and search engine friendly method for redirecting websites. While these is a good search engine optimization factor, you can use it in several situations, including:

• redirecting an old website to a new address

• to setup several domains pointing to one website

• to enforce only one version of your website (www. or no-www)

• to harmonize a URL structure change

There are several ways to setup a 301 Redirect, below I will cover the most used ones:

PHP Single Page Redirection

In order to redirect a static page to a new address simply enter the code below inside the index.php file.


header(“HTTP/1.1 301 Moved Permanently”);


PHP Canonical Redirecting

The Canonical 301 Redirect will add (or remove) the www. prefixes to all the pages inside your domain. The code below redirects the visitors of the version to


if (substr($_SERVER[‘HTTP_HOST’],0,3) != ‘www’) {
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: http://www.’.$_SERVER[‘HTTP_HOST’]


Read Also: 7 Ways To Make Your Website Loading Times Faster

Apache .htaccess Singe Page Redirect

In order to use this method you will need to create a file named .htaccess (not supported by Windows-based hosting) and place it on the root directory of your website, then just add the code below to the file.

Redirect 301 /old/oldpage.htm /new/

Apache .htaccess Canonical Redirection

Follow the same steps as before but insert the code below instead (redirects all the visitors accessing to

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc]

Read Also:  How To Secure Your WordPress Site With A Few Clicks Of A Button

ASP Single Page Redirect

This redirecting method is used with the Active Server Pages platform.


Response.Status=”301 Moved Permanently”


ASP Canonical Redirect

The Canonical Redirecting method with ASP must be located in a script that is executed in every page on the server before the page content starts.

If InStr(Request.ServerVariables(“SERVER_NAME”),”www”) = 0 Then
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.”
& Request.ServerVariables(“HTTP_HOST”)
& Request.ServerVariables(“SCRIPT_NAME”)
End if


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.