SEO School: 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.

For IP Redirection Use:

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

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]

SEO Webmaster Tags: , , , , , , , , , , , , , , , , ,

SEO Webmaster Related posts

Leave a Reply

You must be logged in to post a comment.

GOOGLE TOP 10
Google ads