Forum Moderators: phranque

Message Too Old, No Replies

Duplicate, submitted URL not selected as canonical (Search Console)

         

anthonyinit

2:22 am on Jan 14, 2021 (gmt 0)

10+ Year Member



Hello Dear All,
Happy New Year to you all :)

I was going through my google new search console this morning and found out this error under "coverage"
Duplicate, submitted URL not selected as canonical
Status:
Excluded


My website has a subdirectory which I have put my second script and it looks like this.

https://www.example.com/mysubdirectory/index.php


now my main website is this
https://www.example.com
and this is my main script.
and in my subdirectory
https://www.example.com/mysubdirectory/index.php
I have installed another script.

Google index my main site just fine
https://www.example.com
with all the pages but on the other hand, google having some issue indexing some of my second scripts URLs

eg.
https://www.example.com/mysubdirectory/index.php
(This is perfectly indexed by google)

https://www.mylinkconverter.com/mysubdirectory/how-to-1
https://www.mylinkconverter.com/mysubdirectory/how-to-2
https://www.mylinkconverter.com/mysubdirectory/how-to-3
https://www.mylinkconverter.com/mysubdirectory/how-to-4

Not index by google (Excluded)

So how can I fix this canonical issue?

On my second script head.php i have this
 <link rel="canonical"
href="<?php echo $canonical_url ?>"/>

and in my index.php i have something like this
<?php
require_once __DIR__ . "/system/config.php";
$current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$parse_main_url = parse_url($config["url"]);
$parse_current_url = parse_url($current_url);
$canonical_url = $current_url;
$slug = substr(str_replace($parse_main_url["path"], "", $parse_current_url["path"]), 1);
$content["content_type"] = -1;
preg_match('/watch\?v=(.*)/', $_SERVER["REQUEST_URI"], $watchSlug);
if (isset($_GET["lang"]) != "") {
if (language_exists(clear_string($_GET["lang"])) === true) {
$_SESSION["current_language"] = clear_string($_GET["lang"]);
require_once(__DIR__ . "/language/" . $_SESSION["current_language"] . ".php");
}else if (isset($_SERVER["HTTP_REFERER"]) != "") {
redirect($_SERVER["HTTP_REFERER"] . "?lang=" . $_GET["lang"]);
} else {
redirect($config["url"]);
}
} else {
$canonical_url .= "?lang=" . $_SESSION["current_language"];
}

FYI.
https://www.mylinkconverter.com/mysubdirectory/how-to-1
https://www.mylinkconverter.com/mysubdirectory/how-to-2
https://www.mylinkconverter.com/mysubdirectory/how-to-3
https://www.mylinkconverter.com/mysubdirectory/how-to-4

These pages not really in the directory it is generated by the script "i don't know how to explain this properly :( "

Thank you

phranque

6:01 am on Mar 9, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



how can I fix this canonical issue?

have you solved this problem yet?
$canonical_url = $current_url

this looks like it will set the canonical url to be the same as the requested url.
is that what you want? (i.e., is that actually the correct/canonical url)

have you checked your web server access log file to see what happens when googlebot requests these urls?