This happens to every page on my site.... One I'll use as an example is: https://mydomain.org/plan-your-visit

When viewing the page source through the browser to see all the metatags... without the metatag module, simply using drupal's default or the global redirect's canonical tag, the canonical link is as expected - a relative link which is simply: href="/plan-your-visit"

However, with the metatag module active, the source will show either of two different canonical urls, depending on if the page was first viewed (and cached) by the admin or by an anonymous visitor to the site (such as me, logged out).

If the anon visitor comes first, the generated metatag is
<link rel="canonical" href="https://mydomain.org/plan-your-visit?q=plan-your-visit" />
(An absolute link, but notice the query string -- which is NOT visible in the address bar.)

When I am logged in (administrator), even more is added to the query string (again not seen in the address bar) and it becomes:
<link rel="canonical" href="https://mydomain.org/plan-your-visit?q=plan-your-visit&amp;SSESS7b2(hashremoved)=(hashremoved)&amp;Drupal_tableDrag_showWeight=0&amp;DrupalModuleFilter=activeTab=all&amp;has_js=1" />

Thinking maybe something is wrong with the url token, I've replaced the url token with something random, like "123", and the result (without any token at all) is very similar but obviously not a real url:
<link rel="canonical" href="123?q=plan-your-visit&amp;SSESS7b2(hashremoved)=(hashremoved)&amp;Drupal_tableDrag_showWeight=0&amp;DrupalModuleFilter=activeTab=all&amp;has_js=1" />

So, whatever is happening, it comes after the url token is generated and used. (I've confirmed the token itself is correct -- when using it elsewhere on a page the result is a simple clean correct url).

I've been trying to figure this out, off and on, for the last several weeks as I have time to mess with it. I've tried several releases of the metatag module, including the latest dev release, (each time uninstalling from the db and completely deleting the files) and get the same result each time. Apparently others aren't having this issue, so perhaps the underlying problem isn't with the metatag module itself, but rather something the module is referencing as it creates that canonical tag...... But what?.... Any suggestions? Any known incompatibilities with other modules?

Comments

bca-wm created an issue. See original summary.

DamienMcKenna’s picture

Issue summary: View changes

That's very strange, it shouldn't be doing that. Obviously ;)

What token are you using for the URL?

bca-wm’s picture

I'm just using the default token, [current-page:url:absolute]

But any other url-related token I've tried will do the same thing... give the expected url it was supposed to, but with the extra query-string stuff tacked on to the end of it.

bca-wm’s picture

Finally figured out which module is adding the query string to the canonical metatag!

I created a separate full copy of the site and began uninstalling modules one at a time, clearing the metatag cache and refreshing the source view between each module uninstall. Determined it to be the CiviCRM module. (When it is turned off, the extra string on the canonical metatag goes away. Turn it back on and the extra string reappears.) I was using the 4.6.3 release of CiviCRM, just updated to the 4.6.8 release, but the problem remains.

Still unsure why though.

bca-wm’s picture

Since figuring out the cause being CiviCRM this morning, I've been looking deeper, and realize I stumbled into a proverbial can of worms.

The issue is already known and supposedly "fixed", although I beg to differ on that. (See https://issues.civicrm.org/jira/browse/CRM-16495.) And I also found a few other threads about trying to allow query strings through the metatags module to appear in the canonical link, although that hasn't been developed yet.

The link given above pointed me to the file: /sites/all/modules/civicrm/drupal/civicrm.module. Around line 300 (in release 4.6.7) is some code regarding altering metatags. I commented out that section of code and that resolved the incorrect canonical url issue on my site.... I don't really like hacking modules, but in my specific case, most of how I am using the CiviCRM backbone is actually done through the Views module and backend interactions with other modules. So I don't really need canonical links on Civi's built in displays because, for the most part, I'm not using them.

So I guess this issue could be "closed" here, since the needed changes would be with the CiviCRM module.....

As mentioned, there are a few threads here in the Metatag issues list about getting a feature for query strings to pass through into the canonical url. Perhaps what CiviCRM's code is trying to do in this regard could be better handled by such a feature in Metatag itself?

DamienMcKenna’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Component: Other tags » Code
Status: Active » Closed (works as designed)

I suspect you should take it up with the CiviCRM community.