title: php - creating a dynamic canonical url
body: <p>Currently on my site I have duplicate URLs as follows:</p>
  
  <pre><code>example.com/post_title/
  example.com/post_title_2/
  example.com/post_title_33/
  </code></pre>
  
  <p>I have a canonical url set up in my site's header file that's used on every page as so:</p>
  
  <pre><code>&lt;link rel="canonical" href="&lt;?php echo $url ?&gt;" /&gt;
  </code></pre>
  
  <p>where $url is the page url. So for example if the page URL is example.com/post_title_33/, the canonical is example.com/post_title_33/</p>
  
  <p>My question is what would be the best way to make it so the canonical URL is always example.com/post_title/?</p>
  
  <p>The numbers at the end of the URL can be any number not just 2 or 33 like I used in my example.</p>