GaryTheScubaGuy
Canonicalizations, 301's and server settings update
by
on 25 June 2011 at 12:10 am (331 Views)
Hi All, (and thanks to JaqiC for the public thank you!)
I wanted to add something to this thread before going on because based on PM's and posts I can see this is an issue for many. Plus I forgot to add the actual IP to the list of redirects.
On a side note Google can probably see and resolve many of these instances, but for me just like using keywords in the meta, if it doesn't hurt to do then I am doing it. (and by the way I have done considerable testing on both canonicals, 301's, keywords and have not seen the slightest issue with Google. In fact on a few tests 3rd party sites showing improved rankings (Yahoo, Dogpile, etc.)
Depending on what type of hosting you have this is a very easy fix. Because most Affiliates I know are in gaming and are portal sites canonicalization is of little concern (but still important if you have external links pointing to more than one) but anyone using xml or other types of feeds that use dynamic URL's really need to use this, as well as the previously mentioned 'absolute' linking structure and canonicals.
Anyhow here are specific instructions I gave someone awhile back that outline specific setups;
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.htmlNotice 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:
or
redirect permanent /old-file.html http://www.yourdomain.com/new-file.html
/old%20file.html http://www.yourdomain.com/new-file.htmlApache 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 use 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 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.comSince 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 hurt your rankings without warning assuming that you have a higher potential of spam from duplicate content. Google generally does not notify webmasters of penalties, so you could be spending years trying to resolve an issue like this. Make all your links Absolute (Full URL) at least to 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, an old Mac Platform web serverthat has no redirect capabilities.
domain.com/
www.domain.com/
www.domain.com
domain.com/index.html
www.domain.com/index.html
ALWAYS:Now for the .htaccess canonical redirect for the NON-www. to the www.
<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
RewriteEngine OnA More advanced version will even allow you to 301 your IP address and any subdomains:
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]
RewriteEngine OnThe above code will 301 your non-www to your www, as well as redirect your IP address as a 301 to your www.
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
For IP Redirection Use:RewriteCond %{HTTP_HOST} ^12\.34\.567\.890To redirect your http pages but NOT your https pages use:
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
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} ^80301 Redirects & Canonical Redirects:
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L,QSA]
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:
PHP 301 Redirect
- Open Internet Services Manager then "right-click" on the file or folder you want to redirect to a new page or folder.
- Select "redirection to a URL".
- Enter the URL where you want the redirect to go to.
- Check the fields: "exact url entered above" and "A permanent redirection for this resource".
- Click "Apply".
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:<?phpPHP Canonical Redirect:
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.new-url.com/');
?>
(non-www to www)<?phpRedirects & Canonical Redirects for Active Server Pages (ASP)
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']);
}
?>
Single Page Redirect:
This is placed on the page you are redirecting and is triggered when someone tries to access the page.<%@ Language=VBScript %>ASP Canonical Redirect:
<%
Response.Status="301 moved permanently"
Response.AddHeader "Location", "http://www.domain.com/"
%>
(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
%>
Tags:
canonical redirects 301
- Categories
- Uncategorized




