SEO Class

Canonical Redirects .htaccess and SEO

Posted April 1st, 2007 by SEO Class Admin

Canonical redirects, .htacess files and proper linking are important for SEO. These are important factors and impact the ranking of a website in a number of ways. If you have people linking to the www.domain.com and others linking to domain.com (non-www) then you will split the number of inbound links to your domain. Search engines see the www and non-www versions as two distinct pages. This also has an impact on your Google Page Rank (PR). So by implementing the redirects properly in the .htaccess file (for Apache) and the ISAPI filters in windows you will improve the ranking of your home page.

Another simple thing to do is to link to “/” throughout the site when you want to link to the home page and not link to index.html etc. This also improves the consistency of the links and again will improve PR and inbound link strength.

For Unix/Linux web servers you will go to the root directory of your site and look for a file called .htaccess and if it exists you can open it in notepad and modify it. If it does not exist you can create a files in notepad, upload it and then rename it to .htacess with no extention.

Here is a sample of a redirect from the non www to the www:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.seoclass\.org [NC]
RewriteRule (.*) http://www.seoclass.org/$1 [R=301,L]

If you choose to instead redirect the www to the non www:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.seoclass\.org [NC]
RewriteRule (.*) http://seoclass.org/$1 [R=301,L]

(We simply removed the www from the third line)

Here is a good sample .htaccess file that works for the www to non www and sub-directories and sub-files also redirect:

* please note: copy and paste the below and name file htaccess.txt and once ftp over to remote rename to .htaccess

—– sample .htaccess for regular html sites ———-

<IfModule mod_rewrite.c>
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

</IfModule>

——

For wordpress here is a good sample .htaccess file

——–sampel .htaccess for wordpress ———

# This is a good htaccess file sample by SEOClass.org

<IfModule mod_rewrite.c>

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^seoclass\.org$ [NC]
RewriteRule ^(.*)$ http://seoclass.org/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

——–

What you can do is take a look at the PR of the existing www and non www versions and whichever is higher make that the primary. Also check to see inbound links to each of the two and compare them and base your decision off both factors.

Once you decide on a set url, people will begin to bookmark it and link to it naturally. Whenever you submit a link to a site or directory you should always continue to use the same consistent URI or URL.

Redirecting One domain name to another (301 Permanent Redirects):

301 Redirect Examples Sample Code in .htaccess

Permanent 301 Redirect for Apache using .htaccess from one domain to another
(pointing multiple domain names to one .htaccess sample 301)

Redirect 301 / http://www.newdomain.com/

The above code is to be used when pointing multiple domain names to one domain (the main site) . This is often done by businesses wishing to protect their trademark by purchasing similar names and various top level domain names (TLD) for their company. This is also good for companies wishing to capture type in traffic of users who type keywords straight into the toolbars or their url area of the browser.

Rewrite for Apache using .htaccess from home page to a sub directory and 301 status

RewriteEngine on
RewriteRule ^index\.html$ http://www.domainname.com/newdirectory/index.html [R=301,L]

Permanent 301 Redirect for IIS

In IIS Internet Services Manager: right click on the file or folder you want to redirect. Select the radio titled “a redirection to a URL”. Enter the redirection page, check “The exact url entered above” and the “A permanent redirection for this resource”. Click “Apply”.

Permanent 301 Redirect Code in ASP (This goes in an asp file sitting on the server)

<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently” Response.AddHeader “Location”, ” http://www.newdomainname.com/”
%>

Permanent 301 Redirect in ASP .NET (This goes in an asp file sitting on the server)

<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”,”http://www.newdomainname.com/”);
}
</script>
Note regarding IIS 301 Redirects:

ASP and ASP.net permanent redirects will not work unless the original files needing redirection use the .asp or .aspx file extensions.