Skip to content

Commit

Permalink
Fix issues with noindex/canonical reference on homepage.
Browse files Browse the repository at this point in the history
  • Loading branch information
modusinternet committed Apr 12, 2022
1 parent 6f249c7 commit 4e91d92
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
34 changes: 17 additions & 17 deletions ccmslib/_default.php
Expand Up @@ -89,29 +89,29 @@ function ccms_hrefLang_list() {
function ccms_canonical() {
global $CFG, $CLEAN;

// Only use this feature on the homepage to help prevent dupicate indexing attempts
// by search engines when dealing with language dir.
// ie:
// https://yourdomain.com
// vs
// https://yourdomain.com/en/
//
// Both would contain the same content so we want Google to not index the normal domain, an index the one containing the /en/ dir instead.
// The reason for this is, depending on what language page your currently viewing a site in, (eg: /en/, /fr/, /sp/). the root page
// content will look exactly the same, when using CustodianCMS, as the one found in the language specific sub dir.
// ie:
// https://somedomain.com and https://somedomain.com/cx/
//
// We need to tell search engines not to index the content on the https://somedomain.com but go ahead and index the content on the
// https://somedomain.com/cx/ page.
/*
Only use this feature on the homepage to help prevent dupicate indexing attempts by search engines when dealing with language dir.
ie:
https://yourdomain.com
vs
https://yourdomain.com/en/
Both would contain the same content so we want Google to not index the normal domain, an index the one containing the /en/ dir instead. The reason for this is, depending on what language page your currently viewing a site in, (eg: /en/, /fr/, /sp/). the root page content will look exactly the same, when using CustodianCMS, as the one found in the language specific sub dir.
ie:
https://somedomain.com
and
https://somedomain.com/cx/
We need to tell search engines not to index the content on the https://somedomain.com but go ahead and index the content on the https://somedomain.com/cx/ page.
*/

if($_SERVER['REQUEST_URI'] === "/"){
// if the visitor is looking at the root of the website WITHOUT the language dir.
// The visitor is looking at the root of the website WITHOUT the language dir.
// ie: https://yourdomain.com
echo '<meta name="robots" content="noindex" />';
echo '<link rel="canonical" href="' . $_SERVER['REQUEST_SCHEME'] . "://" . $CFG["DOMAIN"] . "/" . $CLEAN["ccms_lng"] . '/" />';
} else {
// if the visitor is looking at the root of the website WITH the language dir.
// The visitor is looking at the root of the website WITH the language dir.
// ie: https://yourdomain.com/en/
echo '<link rel="canonical" href="' . $_SERVER['REQUEST_SCHEME'] . "://" . $CFG["DOMAIN"] . $_SERVER['REQUEST_URI'] . '" />';
}
Expand Down
19 changes: 17 additions & 2 deletions ccmspre/index.php
Expand Up @@ -981,8 +981,22 @@ function CCMS_Main() {
$etag = md5($CLEAN["ccms_tpl"]) . "." . $row["date"];
header("ETag: " . $etag);

$search = "{NONCE}";
$replace = $CFG["nonce"];
/*
The nonce search and replace is neccesary in order to help makesure Content-Security-Policy's (nonce validation in templates specificaly) remain valid and secure regardless of where it comes from, dynamicly generated or simply pulled from the cache.
The canonical update is neccesary because we don't ever want the index page to be crawled by spiders if the URI doesn't contain a language code. The problem we have to deal with in this case is that the index page of a site may be either dynacically generated or pulled from the cache. In both cases we must be sure that the <meta name="robots" content="noindex" /> tag IS SENT to the visitor if the language declaration IS NOT found in the URI. (Even if it's sent twice.)
ie: https://yourdomain.com
And that the <meta name="robots" content="noindex" /> tag IS NOT sent to the visitor if the language declaration IS found in the URI.
ie: https://yourdomain.com/en/
*/
if($_SERVER['REQUEST_URI'] === "/"){
$search = array('{NONCE}','<link rel="canonical" href="');
$replace = array($CFG["nonce"],'<meta name="robots" content="noindex" /><link rel="canonical" href="');
} else {
$search = array('{NONCE}','<meta name="robots" content="noindex" />');
$replace = array($CFG["nonce"]);
}

echo str_replace($search, $replace, $row["content"]);
} else {
// Cached template IS expried. It should be removed, rebuilt and recached.
Expand Down Expand Up @@ -1122,6 +1136,7 @@ function CCMS_Main() {
//echo CCMS_TPL_Parser($buf);
CCMS_TPL_Parser($buf);
} else {
//echo "ccms_tpl=[" . $CLEAN["ccms_tpl"] . "]";
echo '<div style="margin:100px auto;text-align:center"><img src="https://custodiancms.org/cross-origin-resources/404-animated-ascii.gif" style="display:block;margin:0 auto" /><br>Under Construction</div>';
}
}
Expand Down
4 changes: 2 additions & 2 deletions ccmsusr/index.php
Expand Up @@ -9,8 +9,8 @@
$CFG = array();
$CLEAN = array();

$CFG["VERSION"] = "0.7.7";
$CFG["RELEASE_DATE"] = "Mar 31, 2022";
$CFG["VERSION"] = "0.7.8";
$CFG["RELEASE_DATE"] = "Apr 12, 2022";

// Necessary to solve a problem on GoDaddy servers when running sites found in sub folders of existing sites.
if(isset($_SERVER["REAL_DOCUMENT_ROOT"])) {
Expand Down
4 changes: 2 additions & 2 deletions index.php
Expand Up @@ -9,8 +9,8 @@
$CFG = array();
$CLEAN = array();

$CFG["VERSION"] = "0.7.7";
$CFG["RELEASE_DATE"] = "Mar 31, 2022";
$CFG["VERSION"] = "0.7.8";
$CFG["RELEASE_DATE"] = "Apr 12, 2022";

// Necessary to solve a problem on GoDaddy servers when running sites found in sub folders of existing sites.
if(isset($_SERVER["REAL_DOCUMENT_ROOT"])) {
Expand Down

0 comments on commit 4e91d92

Please sign in to comment.