freshpromo Toronto SEO
seo firm    about    contact
home :: seo plans :: web design :: portfolio :: blog :: free seo quote :: knowledge
knowledge center :: seo tools home

How Do I Implement a 301 Redirect?

A 301 redirect allows visitors and search engines to access a web page after it has been moved. If you have changed the domain name of your web site or changed the file names of pages, then you need to link to the new URLs for visitors and search engine spiders. The 301 permanent redirect is the most search engine-friendly method of redirection to the new URL or page and is the current standard for SEO purposes. Here are instructions on how to code a 301 redirect, depending on your system.

.htaccess 301 Redirect

If the .htaccess file does not exist, create a new file with no trailing extension after the ".htaccess" using a plain text editor (Remember to put the period at the beginning of the file name!). For a Mac, we recommend BBEdit; for Windows, TextPad. Upload it to the root directory of your old web site. Usually that's in /public_html or /www on your server. *Note: your web server must be a Linux system and have Apache mod_rewrite module enabled.

Add the following to your .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.new-site.com/$1 [R=301,L]

If you decide to change filenames of individual pages of your site, you can redirect the old URLs to the new URLs by using the following line as an example:

redirect 301 /old_page.html http://www.yourdomain.com/abc/new_page.html

PHP Redirect:

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-domain.com" );
?>

In ASP:

Open the old web page and replace all its content with the following code, replacing "www.new-location.com" with the file name of the new page.

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.new-location.com"
%>

In ASP .NET:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-location.com");
}
</script>

In IIS (on a Windows server):

1. In internet services manager, right click on the file or folder you wish to redirect.
2. Select "a redirection to a URL".
3. Enter the redirection page.
4. Check "The exact url entered above", and the "A permanent redirection for this resource".
5. Click "Apply".

In ColdFusion:

Add the following to the ColdFusion page:

<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-site.com">

Canonical Issues - Redirecting non-www to www:

Some webmasters prefer to redirect domain.com to www.domain.com for search engine optimization purposes. The thought is that some incoming links point to their non-www domain and some point to the www domain. So if the domains are consolidated, incoming links are as well. Webmasters who use this redirect usually see instances of search engine rankings with and without the www in their listings and want to consolidate their efforts.

Canonical Redirect using .htaccess

Add the following four lines to your .htaccess file, replacing 'domain.com' with your site's domain. Remember, you need to be hosted on a Linux server with the Apache Mod-rewrite module enabled.

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

Canonical Redirect using IIS 7.0

For this to work, you need to download and enable the URL Rewrite module for IIS 7. Then the following code is used in the ASP.NET web.config file:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"
               redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

 

If you need further help setting up a 301 redirect or any other aspect of web development, post your question as a comment in John Metzler's blog and he'll do his best to respond.


Share these instructions with your own website visitors or friends! Simply copy and paste the HTML code below into your web site, blog, or emails.

Top SEOs Best in Search award - Search Engine Optimization August 2010

FreshPromo's on Twitter!


Bookmark this page:

| More

Free SEO Tips

> 8 Link Popularity Methods Ranked for SEO

> Google Webmaster Guidelines You May Be Overlooking

> Predicting Search Engine Algorithm Changes

> How Web Design Can Affect Search Engine Rankings

more...

Professional SEO Firm | Site Map
© 2010, freshpromo. All rights reserved. SEO firm Toronto, GTA, Ottawa, Montreal.