Redirect from SSL URLs to non-SSL URLs in Zencart

A client of the company I work for pointed out a problem in which some how the SSL version of his website got indexed into Google and other search engines.  Now this posed a problem for the client as search engines don’t rank web pages well which can be referenced from two or more different urls.

As the website was in Zencart I knew that there was no option than to write code to effect redirection from SSL to non-SSL url.

So, I opened the html_header.php file present in the includes/templates/<Your_Template>/common folder and wrote the following code at the top:

<?php
if ($_SERVER['HTTPS'] == 'on') {
if (isset($_GET['main_page'])) {
$strMainPage = $_GET['main_page'];
switch($strMainPage) {
case 'index':
case 'product_info':
case 'privacy':
$strURL = "https://". $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
$arrFrom[] = "https://";
$arrTo[] = "http://";

$strURL = str_replace($arrFrom,$arrTo,$strUrl);
header("Location: $strUrl");
exit;
}
}
}
?>

The above code helped redirect those pages whose SSL version got indexed by mistake into the search engines. If you note from above I have not redirected post shopping cart pages as they need to be running in secure mode so that customer can enjoy safe and secure shopping.

Leave a Comment