All About 301 Redirect

There will be a time when we have to move our website into a different folder or a hosting account which will cause a change of permalinks or the URL itself. These changes are critical especially when it comes to search engine optimization for it affects google page rank and book marks from browsers and from social sites. URL redirection is the only solution for these changes and the best way to preserve the SEO of your site is 301 redirection. You can do this through your domain manager or through the webhost cpanel and use a godaddy if you want to obtain a new domain.

301 redirection is the safest solution when there is a change of filename of a webpage or if it has been moved around. The code 301 means “moved permanently”.  301 are very useful in cases where:

  • A site has been moved to a different URL and you want the transition to be seamless.
  • The website can be accessed through different URLs. Ex. or
  • The website is being merged with another website and you want to make sure the outdated pages points to the updated pages.

There are different ways in setting up a 301 redirect, it can be complex depending on the scripting language or server used but mostly are simple and requires only a few lines, actually almost all are simple except maybe for some cases. Here are some of the ways you can use 301 redirect:

PHP  301 Redirect for Webpages

Modify index.php

header("HTTP/1.1 301 Moved Permanently");

PHP 301 Redirect for the whole URL

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']

Single Page Redirect for Apache

Create a .htaccess in the root directory and add the line.

Redirect 301 /old/oldpage.htm /new/

Apache URL 301 redirect

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

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

For ASP webpage redirect

Response.Status="301 Moved Permanently"

ASP URL 301 redirect

The Canonical Redirect 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

If you encounter problems redirecting, you can also contact your web hosting provider regarding 301 redirect for they may have a better solution and some web hosting have security tools in the server that may hinders you from adding script like .htaccess. Some platforms like WordPress has also plugins that automates redirection.

With 301 redirect, you can now save your precious Google page ranks and keep the SEO of your site.

Leave a comment

Your email address will not be published.


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