search engine optimization and search engine marketing company seo company jobs
Search Engine Optimization ServicesMarketing ServicesWeb Design ServicesSEO ToolsSEO TutorialsSEO Company Contactnav
shadow
SEO Tutorials from SEO Image

301 Redirects & Canonical URL Issues Tutorial
Registered ©2006 SEO Image, Inc

When you move a file on your server you want to be certain that you pass the proper redirect directive to the browsers and more importantly, the Search Engines. The 301 redirect is the only redirect we recommend for anyone o use without advanced knowledge of using redirects. 302 redirects are actually used by SEO's for some specific reasons such as moving domain names from an old domain.com to a new domain.com

Apache | ASP | ASP.NET | Windows IIS | Coldfusion | Sun

301 Redirects & Canonical Redirects for Apache

This is done on the invisible file named ".htaccess" this file is located in the root of your Web Server.

For a single page redirect (NEVER use a 302 make sure it says either "Permanent" or "301" in the file if it doesn't it will pass a 302 by default:

redirect 301 /old-file-name-html http://www.yourdomain.com/new-file.html

or

redirect permanent /old-file.html http://www.yourdomain.com/new-file.html

Notice all that is needed is one space between the old path and the new URL. The new URL must contain an Absolute URL: meaning it uses http://www.yourdomain.com/yourfile.html. If there is a space in the file name use %20 otherwise it will not work, you can only leave one space and that is between the old file path and the new url. Here is an example:

/old%20file.html http://www.yourdomain.com/new-file.html

Apache Server Canonical Redirect
(non-www to www):

This should always be done as some search engines do not properly understand the difference and may count it as a duplicate page, additionally if you us domain.com/index.html or domain.com index.php the Search Engine might get lost. Since Google is the most popular Search Engine, it also happens to be the least advanced with canonical issues and redirects. Google is also in a major anti-spam battle so it would actually hurt your rankings unintentionally as its a bit archaic in its handling of canonical issues and redirects. What Google will see as the same page duplicated on your site (In reality its all the same page).

domain.com
domain.com/
www.domain.com/
www.domain.com
domain.com/index.html
www.domain.com/index.html

Since Google favors penalties over relative content you need to make sure you NEVER link to your home page as "index.html" or any other file extension. The automated factors of the Google algorithm would ban you without warning, and Google makes it a policy to not notify webmasters of penalties, so you could be spending years trying to resolve an issue like this. Make all your links Absolute to a least your home page so any link on your site should always link to "http://www.yourdomain.com/" be sure to use the trailing slash as some servers will pass a redirect to the trailing slash if you do not, and this will be a 302 redirect. This is a known issue on WebStar Server a Mac Platform.

ALWAYS:
<a href="http://www.yourdomain.com/">
NEVER:
<a href="http://www.yourdomain.com/index.html"> -Not direct to the domain.
<a href="http://www.yourdomain.com"> - No Trailing Slash

Now for the .htaccess canonical redirect for the NON-www. to the www.

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

NOTE: Some Versions of Apace require an extra line or two of code for SymLinks and a different structure of the rewrite rule as follows:

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

A More advanced version will even allow you to 301 your IP address and any subdomains:

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

The above code will 301 your non-www to your www, as well as redirect your IP address as a 301 to your www.

To redirect your http pages but NOT your https pages use:
Say for instance, your secure certificate was not created as www.domain.com, but was instead issued as domain.com then you would need to use the following and be sure to combine this with ABSOLUTE links (absolute links use the full URL), or you may unintentionally cause duplicate https and http paths.

RewriteCond %{SERVER_PORT} ^80
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L,QSA]

 

301 Redirects & Canonical Redirects:
Microsoft IIS Web Servers

To Perform this you need administrative access to the IIS Server Application. If you do not have this then you can do the redirects in ASP or PHP.

Single Page Redirect:

  1. Open Internet Services Manager then "right-click" on the file or folder you want to redirect to a new page or folder.
  2. Select "redirection to a URL".
  3. Enter the URL where you want the redirect to go to.
  4. Check the fields: "exact url entered above" and "A permanent redirection for this resource".
  5. Click "Apply".

PHP 301 Redirect
This is added to the page that you want to redirect to a new page, it is triggered on the request for the specific page and the file will actually return the redirect.

Single Page Redirect:

<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.new-url.com/');
?>

PHP Canonical Redirect:
(non-www to www)

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

Redirects & Canonical Redirects for Active Server Pages (ASP)

Single Page Redirect:
This is placed on the page you are redirecting and is triggered when someone tries to access the page.

<%@ Language=VBScript %>
<%
Response.Status="301 moved permanently"
Response.AddHeader "Location", "http://www.domain.com/"
%>

ASP Canonical Redirect:
(non-www to www):
This code should be inserted into a global include file or any script which is executed for every page on the site before the page output begins. If your programmers are using ASP.net and/or they are not using a global file, you need to have them address this issue or perform the Canonical Redirect from the IIS Server Application (as above).

<%
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
%>

301 Redirects for ASP.NET

For Single Pages:

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

Canonical Redirect for ASP.NET (ASPX):

For ASP.NET you need to do this individually in the Windows IIS Internet Services Manager or Use The ASP Code above in a global file that wil process the redirect BEFORE any other processes.

 

301 Redirects for Macromedia ColdFusion

Since cold fusion is usually hosted on Windows, Linux, and Sun. The .htaccess and Windows IIS tutorials above will have solutions for the Canonical and redirects. This is for a Single Page Redirect embedded directly into the file:

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

 

301 Redirects for Sun Web Servers

In order to do this on a SUN platform you have to rewrite the SUN Web Server's standard action of always using a 302 redirect to always use a 301 redirect. You have to open the obj.conf configuration file and add the following lines below the <Object name="default"> line:

<Client code="302">
Output fn="set-variable" error="301" noaction="true"
</Client>

The above will make the SUN web server to return 301 permanent redirect responses for all redirects. If you only want to use a 301 permanent redirect response for certain URLs or files, you can add following to the bottom of obj.conf:

<Object ppath="path">
<Client code="302">
Output fn="set-variable" error="301" noaction="true"
</Client>
</Object>

 

Top | Apache | ASP | ASP.NET | Windows IIS | Coldfusion | Sun



All Search Engine Optimization Services Include:
Meta Tag Optimization Optimized Title Tags Optimized Content Building
Consulting Services Link Popularity Building Search Engine Submission
Keyword Research Competition Research Internet Marketing Strategies
Web Site Analysis & Reports Monthly Maintenance Industry Best Practices
Pay Per Inclusion Pay Per Click Ranking Guarantee

SEO Image®    115 East 57th Street    11th Floor    New York, NY 10022     888-SEO-COMPANY
1-888-736-2667
Outside the US call: 212-845-9900

Protected by Copyscape
Search Engine Optimization | Web Design | Methodology | Link Building | Site Map | Search Engine Submission
Services | Tutorials | Organic Search Engine Optimization | SEO Company Info | Design Portfolio
Search Engine Marketing | Internet Marketing Services | Search Engines | Case Studies | Company CEO | Link To Us
Contact Us | Blog | Affiliate Program | New York Search Engine Optimization | Legal/Copyright | Privacy Policy
Company BrochureSEO Image Brochure

Associations and Memberships

seo company footer