<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Asghar</title>
    <description>The latest articles on DEV Community by Ali Asghar (@aliasgharcodes).</description>
    <link>https://dev.to/aliasgharcodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4118088%2Feab6efbf-b4c4-4caa-9f04-c7bb233e9d96.png</url>
      <title>DEV Community: Ali Asghar</title>
      <link>https://dev.to/aliasgharcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aliasgharcodes"/>
    <language>en</language>
    <item>
      <title>A canonical tag bug was hiding 800 pages from Google</title>
      <dc:creator>Ali Asghar</dc:creator>
      <pubDate>Wed, 09 Sep 2026 19:11:09 +0000</pubDate>
      <link>https://dev.to/aliasgharcodes/a-canonical-tag-bug-was-hiding-800-pages-from-google-59pd</link>
      <guid>https://dev.to/aliasgharcodes/a-canonical-tag-bug-was-hiding-800-pages-from-google-59pd</guid>
      <description>&lt;p&gt;My Django blog had ~900 posts. Google had indexed almost none of them.&lt;br&gt;
I assumed it was a content quality problem. It was partly that — but there&lt;br&gt;
was a template bug underneath it that made the whole site nearly uncrawlable.&lt;/p&gt;
&lt;h2&gt;
  
  
  Bug 1: the canonical block default
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;base.html&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"canonical"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% block canonical %}{{ site_config.site_name }}{% endblock %}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default value of that block is the site &lt;strong&gt;name&lt;/strong&gt;, not a URL. Only&lt;br&gt;
&lt;code&gt;post_detail.html&lt;/code&gt; overrode it. So every category page, tag page and search&lt;br&gt;
page emitted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"canonical"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"AutomateAI Blog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Google resolves that as a relative path — &lt;code&gt;/category/x/AutomateAI%20Blog&lt;/code&gt; —&lt;br&gt;
which 404s. The page gets dropped. And those category pages were the only&lt;br&gt;
crawl path to the posts.&lt;/p&gt;

&lt;p&gt;The fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"canonical"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% block canonical %}https://example.com{{ request.path }}{% endblock %}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Requires &lt;code&gt;django.template.context_processors.request&lt;/code&gt; in your TEMPLATES&lt;br&gt;
context_processors.&lt;/p&gt;
&lt;h2&gt;
  
  
  Bug 2: paginated pages canonicalising to the homepage
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;home.html&lt;/code&gt; hardcoded it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{% block canonical %}https://example.com{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;paginate_by = 10&lt;/code&gt; and 900 posts that's ~90 pages, all declaring&lt;br&gt;
themselves duplicates of page 1. Google drops them, and the links on them&lt;br&gt;
carry no weight. So the oldest posts were both 89 clicks deep &lt;em&gt;and&lt;/em&gt; on&lt;br&gt;
pages Google had discarded.&lt;/p&gt;

&lt;p&gt;Fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{% block canonical %}https://example.com/{% if page_obj.number &amp;gt; 1 %}?page={{ page_obj.number }}{% endif %}{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to check your own site
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://yoursite.com/category/whatever/ | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; canonical
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"https://yoursite.com/?page=3"&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; canonical
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The category page should return its own URL. The paginated page should&lt;br&gt;
return its own URL, not the homepage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd check first next time
&lt;/h2&gt;

&lt;p&gt;If Search Console shows a lot of "Discovered – currently not indexed",&lt;br&gt;
don't assume it's a ranking problem. Check whether Google can actually&lt;br&gt;
reach the pages at all:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;canonical on category and paginated pages&lt;/li&gt;
&lt;li&gt;crawl depth (how many clicks from the homepage to your oldest post?)&lt;/li&gt;
&lt;li&gt;whether &lt;code&gt;robots.txt&lt;/code&gt; is blocking a path you actually use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mine had all three. The canonical was the one I'd never have found without&lt;br&gt;
curling the raw HTML — it looked fine in the browser.&lt;/p&gt;

</description>
      <category>django</category>
      <category>seo</category>
      <category>webdev</category>
      <category>python</category>
    </item>
  </channel>
</rss>
