We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I got that bit, but there was also this bit:


    Quote
    If you don’t want that, you can use a template variable to customize the canonical URL in templates for pages where you don’t want this behavior.

    I just meant that if you wanted, you could create a Template Variable called "canonical" or something like that, and store your preferred custom value of the canonical URL in that template variable. I wouldn’t recommend this, unless you have some highly specialized reason that you don’t want the canonical URL to be the same as the friendly URL. In the vast majority of cases, just use the appropriate code as posted above and you’ll get canonical URLs the same as your friendly URLs, which is almost always what you want.
      • 3749
      • 24,544 Posts
      Or just install the Canonical snippet and put a tag for it in your template. You can easily customize the snippet to do whatever you want.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36711
        • 68 Posts
        yes, you are right Bob
        actually there are several ways you can implement the canonical tag
        after all, I modyfied my settings and added into the main template the following:
        <link rel="canonical" href="[[++site_url]][[*canonicalTag]]" />
        

        the canonical tag TV input type is set to Text, default value is empty
        I can write in the TV whatever I want when editing the main page and in this case there is no need to change the Symlink’s canonical
        all Symlinks’ canonical would point automatically to its original main page which is what I wanted

        to esnyder
        thanx for your reply, you are right, however what I was describing, it is the case when all your pages are using SE friendly URLs but some of them can be accessed under more than one category as a consequence having more URL addresses each of them SE friendly but creating duplications which should be handled properly by proper use of the canonical tag

        well, I think now it is enough regarding the canonical issue smiley

        thanks for all of your support in this post, i think it is a valuable asset for the community

        reg.
          sherlockseo
          • 33968
          • 863 Posts
          @sherlock: I might have misunderstood what you were doing, but just in case someone else is going to implement this you will need to be very careful with that tag.

          As it stands, with
          <link rel="canonical" href="[[++site_url]][[*canonicalTag]]" />
          

          if [[*canonicalTag]] is empty the link will point to the home page of your site which will confuse the search engines and in the worst case result in the page not being indexed. Effectively you will be telling them ’the content on this page is the same as the home page, so please index that instead’.

          Solution
          You could fix this by adding to your template:
          <link rel="canonical" href="[[++site_url]][[*canonicalTag:default=`[[*id:isnot=`[[++site_start]]`:then=`[[~[[*id]]]]`]]`]]" />
          

          That will return the document url if your TV is empty. I would also consider changing it so you can just enter the resource id in the TV rather than the url alias to minimise typos. Easy mistake to make but can really mess things up!

          Even better...
          If there is a consistent rule for working out which is your ’original’ product page, consider a snippet which would generate the canonical link rather than doing it manually. Let modx do it all for you smiley
          • it is the case when all your pages are using SE friendly URLs but some of them can be accessed under more than one category as a consequence having more URL addresses each of them SE friendly but creating duplications

            Yeah, if you’re linking to the exact same content at different URLs that would be a problem, and a perfect reason to use the Canonical tag, though it would be even better if you can just resolve the duplication such that the content only ever appears at the same URL.

            If you can’t do that, then yeah, you’ll need some consistent scheme for deciding which URL should be canonical and indicating that. Hard to say more without details, but presumably if there is some logical rule for which version you want to be canonical, you should be able to write a snippet to implement that rule.

            Generally I wouldn’t recommend setting up your site this way. If you want to list a resource under several different categories that’s fine, but set it up so that the resource always lives at the same URL regardless of where it’s being linked from.
              • 3749
              • 24,544 Posts
              FYI, in the current version of Revolution, you can actually set the URI of the page when editing a resources, so you can manually enter the desired URI for symlinks and weblinks.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 36260
                • 1 Posts
                Quick question,

                My site has 3 diff templates used in 9 diff pages/URLS

                My question:
                Say the URL for my site is ilovemodx.com..

                Do I paste this code on the head of each template LIKE THIS:

                <link rel="canonical" href="[(site_url)][~[*id*]~]" />


                OR LIKE THIS:
                <link rel="canonical" href="[(ilovemodx.com)][~[*id*]~]" />
                • <link rel="canonical" href="[(site_url)][~[*id*]~]" />


                  [(site_url)] is a system setting tag and gets replaced with ilovemodx.com when parsed.
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 12110
                    • 122 Posts
                    Hello,

                    I need your comment/advice for another canonical link version I’m adressing, in Evo 1.0.5, and thanks for the code examples in that tread.

                    I’m using friendly url (with .php suffix) so
                    <link rel="canonical" href="[(site_url)][~[*id*]~]" />

                    is doing fine for most of my sites and pages.

                    There is one situation where I need somethimg in addition, as I’m adding a parameter with an integer value behind an alias, let’s say an url like www.domain.com/nice-page.php?parameter=8

                    I’ve done it with a snippet that is getting the parameter named [!getParam!] and added Phx to the above code example:
                    <link rel="canonical" href="[(site_url)][~[*id*]~][+phx:if=`[!getParam!]`:isnot=`0`:then=`?reg=[!getParam!]`:else=``+]" />


                    Unfortunately the if/then in the Phx (2.1.4) part does not work, even if the get parameter is 0 the then part will appear. The snippet is giving the right values, from 0 to n. Is there an issue with comparisons in Phx?

                    The snippet i use is

                    <?php
                    $region_id = $_GET['reg'];
                    if($region_id > 0) {print $region_id;}
                    else print "0";
                    ?>


                    I know, it’s more a Phx question with comparison issues but maybe you find it useful here (if it works) and you can help.

                    Thanks!


                    • Try to use "return" instead of "print". "print" may goof up some things, though I am not sure if it would fix your issues.
                        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.