Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URGENT: canonical link does not take into account any actions / ids / getvariables #67

Open
sunnysideup opened this issue Sep 10, 2022 · 2 comments

Comments

@sunnysideup
Copy link

The current implementation for the canonical link is not so good, because it removes any actions / ids / getvariables that often are an integral part of a page (e.g. www.e-commerce.com/products/show/12?version=3).

From what I can see, you could change this by changing the AbsoluteLink for a page, but that may have all sorts of other consequences.

@phil-quinn
Copy link
Collaborator

Hi @sunnysideup!

I think you make a good point!

However I also think that often people would NOT want all the query params passed into the canonical link. So perhaps this should be configurable.

Offhand, I see two logical ways to handle it...

  1. The developer could alter the AbsoluteLink() by using the alternateAbsoluteLink() option on their page's model. I think that might be the most straightforward.

  2. Another way to handle it, that is less straightforward, but might be more flexible, is to add an extend or some such to the Seo::getCanonicalUrlLink() function to allow an extension to alter it.

Which makes the most sense for you?

@sunnysideup
Copy link
Author

sunnysideup commented Sep 14, 2022

Thank you for your swift and kind reply.

This is the real issue I see: this is supposed to be an SEO module and it does many great things, but the end result is actually that you end up potentially reducing your SEO visibility, byby a lot, without realising it. It is a very common pattern to use /URSegment(s)/Action/ID for any type of listing (i.e. anytime you would like to make a dataobject visible as a page). With this canonical url method, you link all of these back to the main page (URLSegment).

In my books, we use canonical urls to standardise the domain name, to standardise the language qualifier, etc....

What I did in my metatags module is that I said: if you have a getCanonicalLink method then add that to the the metatags, otherwise just dont use it at all.

That is, you only need canonical links to fix something, not the other way around.

So - in other words, I would recommend that your otherwise rather excellent module would let the developer set a canonical link if needed rather than assuming they need one.

Here is my temporary fix in Page.php... Obviously a hack, but I like using $_SERVER['REQUEST_URI', because I can not imagine all the pages that maybe in a website and any other approach risks having links blocked from being indexed.

The good news that Google still indexes the pages, but when showing them in the search results, it links it to the parent page, meaning that users do not find what they need.

    public function MetaTags($includeTitle = true)
    {
        $tagString = parent::MetaTags($includeTitle);
        $tagString = str_replace('<link rel="canonical" href=', '<meta name="parentpage" content=', $tagString);
        if(! empty($_SERVER['REQUEST_URI'])) {
            $tagString .= PHP_EOL.'<link rel="canonical" href="'.Controller::join_links(Director::absoluteBaseURL(), $_SERVER['REQUEST_URI']).'"/>';
        }

        return $tagString;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants