Canonical Link displays incorrect

Open to all! Ask other shopowners for help.
Post Reply
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Canonical Link displays incorrect

Post by radhavallabh »

Hi;
The canonical link displays as below while indexing by google.

<link rel="canonical" href="https://www.mydomain.com/www.mydomain.com" />

But it seems not right to me... can you please help and confirm if it displays correctly dear?

If not how to fix it;
Thank you in advance
Very Warm Regds./
radhavallabh


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Canonical Link displays incorrect

Post by burt »

You do not mention what version Phoenix.

I just turned on canonical in v1.0.8.14 and it reacts with correct URLs.
I am not here to build for you.
I am here to build with you. Let's help each other.
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Re: Canonical Link displays incorrect

Post by radhavallabh »

burt wrote: Wed Jun 15, 2022 2:00 pm You do not mention what version Phoenix.

I just turned on canonical in v1.0.8.14 and it reacts with correct URLs.
Sorry my version is 1.0.8.15 dear -

But mine is giving the above stated URLS;
I attach my code for convenience

Code: Select all

class ht_canonical extends abstract_executable_module {

    const CONFIG_KEY_BASE = 'MODULE_HEADER_TAGS_CANONICAL_';

    public function __construct() {
      parent::__construct(__FILE__);
    }

    public function build_link() {
      switch (basename(Request::get_page())) {
        case 'index.php':
          if (isset($GLOBALS['cPath']) && !Text::is_empty($GLOBALS['cPath'])
            && ($GLOBALS['current_category_id'] > 0)
            && ($GLOBALS['category_depth'] != 'top'))
          {
            $canonical = Guarantor::ensure_global('category_tree')->find_path($GLOBALS['current_category_id']);

            return $GLOBALS['Linker']->build('index.php', ['view' => 'all', 'cPath' => $canonical], false);
          } elseif (isset($_GET['manufacturers_id']) && !Text::is_empty($_GET['manufacturers_id'])) {
            return $GLOBALS['Linker']->build('index.php', ['view' => 'all', 'manufacturers_id' => (int)$_GET['manufacturers_id']], false);
          }

          return $GLOBALS['Linker']->build('', [], false);
		  //return $GLOBALS['Linker']->build('index.php', [], false);

        case 'product_info.php':
          return $GLOBALS['Linker']->build('product_info.php', ['products_id' => (int)$_GET['products_id']], false);

        case 'products_new.php':
        case 'specials.php':
          return $GLOBALS['Linker']->build(null, ['view' => 'all'], false);

        default:
          return $GLOBALS['Linker']->build(null, [], false);
      }
    }

    public function execute() {
      $GLOBALS['Template']->add_block('<link rel="canonical" href="' . $this->build_link() . '" />' . PHP_EOL, $this->group);
    }

I am not able to figure out that why my URLS are displaying in a different manner...
Please can you help;
Thank you in advance
Very Warm Regds./
radhavallabh
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Canonical Link displays incorrect

Post by ecartz »

radhavallabh wrote: Wed Jun 15, 2022 2:06 pm

Code: Select all

          return $GLOBALS['Linker']->build('', [], false);
		  //return $GLOBALS['Linker']->build('index.php', [], false);
Well, this looks like you changed the canonical link for the front page.

Did you perhaps have it as

Code: Select all

return 'www.mydomain.com';
at one time? As that, when combined with a base href of https://www.mydomain.com/ would give the URL you describe.

Alternately, did you make a change to Linker or Href? Because I would expect your current version to work, or at least give a different problem.
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Re: Canonical Link displays incorrect

Post by radhavallabh »

ecartz wrote: Wed Jun 15, 2022 2:24 pm
radhavallabh wrote: Wed Jun 15, 2022 2:06 pm

Code: Select all

          return $GLOBALS['Linker']->build('', [], false);
		  //return $GLOBALS['Linker']->build('index.php', [], false);
Well, this looks like you changed the canonical link for the front page.

Did you perhaps have it as

Code: Select all

return 'www.mydomain.com';
at one time? As that, when combined with a base href of https://www.mydomain.com/ would give the URL you describe.

Alternately, did you make a change to Linker or Href? Because I would expect your current version to work, or at least give a different problem.
Yes I use a different Href dear with SEO url; But seems to work fine sitewide yet, confused to why is it causing issue with canonical...
Can there be a solution dear?
Please can you help me fix it;
Thank you in advance;
Regds./
radhavallabh
Can you help me understa
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Canonical Link displays incorrect

Post by ecartz »

Since you are already customizing that line, try

Code: Select all

return HTTP_SERVER . DIR_WS_CATALOG;
Or modify the URL rewriter to return the URL that you want.

@raiwa has a URL rewriter for sale. He might find this a reasonable configuration option (to remap a bare index.php to just the directory). Then you could use the core canonical module.
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Re: Canonical Link displays incorrect

Post by radhavallabh »

ecartz wrote: Wed Jun 15, 2022 2:47 pm Since you are already customizing that line, try

Code: Select all

return HTTP_SERVER . DIR_WS_CATALOG;
Or modify the URL rewriter to return the URL that you want.

@raiwa has a URL rewriter for sale. He might find this a reasonable configuration option (to remap a bare index.php to just the directory). Then you could use the core canonical module.
Thank you so much dear :) ;
Very Warm Regds./
radhavallabh


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply