function _redirectToCanonical(req, res, id, basePath, canonicalSlugName) {
  let newPath = basePath + encodeURIComponent(canonicalSlugName);

  // Append additional path or query string info
  let regex = new RegExp(`^${basePath}(.*?)([?/].*)*$`); // Match path or query string as [2]
  let match = req.originalUrl.match(regex) || [];
  if (match[2])
    newPath += match[2];

  res.redirect(newPath);
}
// Redirect from current page to the canonical URL
Redirect from current page to the canonical URL
Redirect from current page to the canonical URL
function _redirectToCanonical(req, res, id, basePath, canonicalSlugName) {
  let newPath = basePath + encodeURIComponent(canonicalSlugName);
  let regex = new RegExp(`^${basePath}(.*?)([?/].*)*$`); 
  let match = req.originalUrl.match(regex) || [];
  if (match[2])
    newPath += match[2];
  res.redirect(newPath);
}
function _redirectToCanonical ( req , res , id , basePath , canonicalSlugName ) { let newPath = basePath + encodeURIComponent ( canonicalSlugName ) ; let regex = new RegExp ( ` ${ basePath } ` ) ; let match = req . originalUrl . match ( regex ) || [ ] ; if ( match [ 2 ] ) newPath += match [ 2 ] ; res . redirect ( newPath ) ; }
Redirect from current page to the canonical URL
Redirect from current page to the canonical URL
// Append additional path or query string info // Match path or query string as [2]