{"id":98,"date":"2009-07-21T14:31:34","date_gmt":"2009-07-21T14:31:34","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2009\/07\/using_a_canonical_url-shtml\/"},"modified":"2009-07-21T14:31:34","modified_gmt":"2009-07-21T14:31:34","slug":"using_a_canonical_url-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/","title":{"rendered":"Using A Canonical URL"},"content":{"rendered":"<p>\nWebsites that can be accessed from multiple URL&#8217;s aren&#8217;t very search engine friendly.\n<\/p>\n<p>\nSometimes this structure may have evolved by accident as a site was developed at different times on varying technologies. You don&#8217;t want to turn off the old links as that would loose valuable search engine equity, but you don&#8217;t want them scattered on multiple URL&#8217;s either.\n<\/p>\n<p>\nThere is a solution, and that is to use a canonical URL.\n<\/p>\n<p>\nThe easiest is to add a simple link element to the page with it&#8217;s correct canonical URL. For example, if we have a page that can be reached at <code>www.example.com\/test.html<\/code>, <code>example.com\/test.html<\/code> or <code>beta.example.com\/test.html<\/code>. we only want this to be index at <code>www.example.com\/test.html<\/code>, so we can use add a link element as follows&#8230;\n<\/p>\n<div class=\"code\"><code>&lt;link rel=\"canonical\" href=\"http:\/\/www.example.com\/test.html\" \/&gt;<br \/>\n<\/code><\/div>\n<p>\nNotice the use of <code>rel=\"canonical\"<\/code>, this is tells a search engine if it has accessed the page from another URL, it&#8217;s actually meant to be indexed from this URL.\n<\/p>\n<p>\nGoogle, Yahoo and Microsoft have all agreed to support this canonical link element.\n<\/p>\n<p>\nAnother approach is to redirect the user to the page on the correct URL server side. Using Apache, this can be done using a <code>RewriteRule<\/code> and couple of <code>RewriteCond<\/code>&#8216;s.\n<\/p>\n<p>\nUsing the same example, the rewrite rule would be something like this\n<\/p>\n<div class=\"code\"><code>RewriteEngine on<br \/>\nRewriteCond %{HTTP_HOST} !^www.example.com [NC]<br \/>\nRewriteCond %{HTTP_HOST} !^$<br \/>\nRewriteRule ^\/(.*)       http:\/\/www.example.com\/$1 [L,R=301]<br \/>\n<\/code><\/div>\n<p>\nHere we make sure we&#8217;re not already accessing using the correct domain name. If we aren&#8217;t, the we redirect using the <var>L<\/var> flag to make sure this it&#8217;s the last rule run, and <var>R=301<\/var> to issue a 301 Moved Permenantly redirect. Anyone visiting the page on an incorrect domain, will now be redirected to the right page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Websites that can be accessed from multiple URL&#8217;s aren&#8217;t very search engine friendly. Sometimes this structure may have evolved by accident as a site was developed at different times on varying technologies. You don&#8217;t want to turn off the old links as that would loose valuable search engine equity, but you don&#8217;t want them scattered &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using A Canonical URL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[75,79],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-dev","tag-web-development","tag-xhtml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using A Canonical URL - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using A Canonical URL - Robert Price\" \/>\n<meta property=\"og:description\" content=\"Websites that can be accessed from multiple URL&#8217;s aren&#8217;t very search engine friendly. Sometimes this structure may have evolved by accident as a site was developed at different times on varying technologies. You don&#8217;t want to turn off the old links as that would loose valuable search engine equity, but you don&#8217;t want them scattered &hellip; Continue reading &quot;Using A Canonical URL&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2009-07-21T14:31:34+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Using A Canonical URL\",\"datePublished\":\"2009-07-21T14:31:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/\"},\"wordCount\":270,\"keywords\":[\"Web Development\",\"XHTML\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/\",\"name\":\"Using A Canonical URL - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2009-07-21T14:31:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using_a_canonical_url-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using A Canonical URL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using A Canonical URL - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Using A Canonical URL - Robert Price","og_description":"Websites that can be accessed from multiple URL&#8217;s aren&#8217;t very search engine friendly. Sometimes this structure may have evolved by accident as a site was developed at different times on varying technologies. You don&#8217;t want to turn off the old links as that would loose valuable search engine equity, but you don&#8217;t want them scattered &hellip; Continue reading \"Using A Canonical URL\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/","og_site_name":"Robert Price","article_published_time":"2009-07-21T14:31:34+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Using A Canonical URL","datePublished":"2009-07-21T14:31:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/"},"wordCount":270,"keywords":["Web Development","XHTML"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/","name":"Using A Canonical URL - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2009-07-21T14:31:34+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/using_a_canonical_url-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Using A Canonical URL"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}