How to solve canonical URLs issue

First – why to solve canonical URLs (or canonicalization) issue?solving canonical url issue

The most important is to ease crawling of your site by robots and getting your pages into index of search engines.
Let’s assume you may type:
mysite.com
www.mysite.com
mysite.com/
mysite.com/index.php
www.mysite.com/index.php

In essence after calling any of those URLs you see them showing same content on the same page. But that’s you… just imagine that for search engines they ALL are DIFFERENT URLs.
First, search engines getting confused as to which page to consider you main page.
Second, Google (as the most important search engine) assigns its Page Rank to each of those URLs, thus you have PR split between several URLs instead of having all strength in one fist.

This split got its name canonical URLs or canonicalization issue.
How to solve this problem?
1. The easiest with 301 redirect in .htaccess
2. Paying attention all incoming links to your site have the same URL structure (i.e. www.mysite.com)
3. Internal links have the same URL structure if you use absolute URLs.
4. Creating and submitting *.xml sitemap through webmaster panels (Google, Bing)
5. Creating and placing regular sitemap (html, hph, asp etc,) on home page or even all pages of your site – could be aslo an additional navigation benefit for your visitor, not only for SE spiders.

Today we have a look at most effective way: 301 redirect.
What we need is .htaccess file which should be in your domain’s root folder. If you don’t have one, just open a Notepad and name it .htaccess. Yes, the dot should be first sign.
If you have in your root folder htaccess.txt, just rename it to .htaccess. (Note: this is all for apache servers supporting Rewrite Mode. If you don’t know – ask your hosting support.)
Also pay attention module mod_alias is on.

Redirect or RedirectPermanent with mod_alias module:

Redirect 301 /old-page.html http://new-domain.ru/new-page.html

or

Redirect permanent /old-page.html http://new-domain.ru/new-page.html

Each URL should be written in separately, which is a time consuming process.

You may use RedirectPermanent to achieve similar goal:

RedirectPermanent /old-url.html http://new-site.ru/new-url.html

RedirectMatch

I.e. to change old .php pages to new .asp

RedirectMatch /(.*)\.php$ /$1.aspx

Redirect with mod_rewrite

From www to non-www:

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

or

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

Redirect from non-www to www:

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

or

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

Redirect using script or sending headers

HTTP/1.1 301 Moved Permanently
Location: http://www.newdomain.ru/newdir/newpage.htm

PHP Redirect

<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.newdomain.ru/newdir/newpage.htm”);
exit();
?>

ASP Redirect

<%@ Language=VBScript %>
<% Response.Status=“301 Moved Permanently” Response.AddHeader “Location”, “http://www.new-url.com” response.end %>

ASP.NET Redirect

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

ColdFusion Redirect

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

JSP (Java) ????????

<% response.setStatus(301); response.setHeader( “Location”, “http://www.new-url.com/” ); response.setHeader( “Connection”, “close” ); %>

CGI PERL

$q = new CGI;
print $q->redirect(“http://www.new-url.com/”);

Ruby on Rails

def old_action
headers[“Status”] = “301 Moved Permanently”
redirect_to “http://www.new-url.com/”
end

Redirect for nginx

if ($host = ‘www.domain.com’ ) {
rewrite ^(.*)$ http://domain.com$1 permanent;
}

——————-

* After solving canonical URLs issue your Page Rank will eventually get better, but it’s unlikely to be visible until a next update.

Related Posts with Thumbnails

Speak Your Mind