From 4e91d92dc91c2c3caf63d78252b2a55e69df3bb3 Mon Sep 17 00:00:00 2001 From: modusinternet Date: Tue, 12 Apr 2022 13:12:44 -0700 Subject: [PATCH] Fix issues with noindex/canonical reference on homepage. --- ccmslib/_default.php | 34 +++++++++++++++++----------------- ccmspre/index.php | 19 +++++++++++++++++-- ccmsusr/index.php | 4 ++-- index.php | 4 ++-- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/ccmslib/_default.php b/ccmslib/_default.php index 6af0b90..4fa5794 100644 --- a/ccmslib/_default.php +++ b/ccmslib/_default.php @@ -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 ''; echo ''; } 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 ''; } diff --git a/ccmspre/index.php b/ccmspre/index.php index ef9996a..98abd7d 100644 --- a/ccmspre/index.php +++ b/ccmspre/index.php @@ -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 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 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}',''); + $replace = array($CFG["nonce"]); + } + echo str_replace($search, $replace, $row["content"]); } else { // Cached template IS expried. It should be removed, rebuilt and recached. @@ -1122,6 +1136,7 @@ function CCMS_Main() { //echo CCMS_TPL_Parser($buf); CCMS_TPL_Parser($buf); } else { + //echo "ccms_tpl=[" . $CLEAN["ccms_tpl"] . "]"; echo '

Under Construction
'; } } diff --git a/ccmsusr/index.php b/ccmsusr/index.php index 7fc7fdb..7dd6193 100644 --- a/ccmsusr/index.php +++ b/ccmsusr/index.php @@ -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"])) { diff --git a/index.php b/index.php index d804ac7..47f756b 100644 --- a/index.php +++ b/index.php @@ -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"])) {