Skip to content

Instantly share code, notes, and snippets.

@eriksimonic
Last active August 29, 2015 14:19
Show Gist options
  • Save eriksimonic/1872df09cb8208da5bf1 to your computer and use it in GitHub Desktop.
Save eriksimonic/1872df09cb8208da5bf1 to your computer and use it in GitHub Desktop.
Quick and dirty hack to force Google reindex on magento store.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW">
</head>
<body>
<?php
/**
* Created by PhpStorm.
* User: erik.simonic
* Date: 20.4.2015
* Time: 10:11
*/
if (version_compare(phpversion(), '5.2.0', '<')) {
echo 'It looks like you have an invalid PHP version. Magento supports PHP 5.2.0 or newer';
exit;
}
error_reporting(E_ALL | E_STRICT);
$mageFilename = getcwd() . '/app/Mage.php';
if (!file_exists($mageFilename)) {
echo 'Mage file not found';
exit;
}
require $mageFilename;
if (!Mage::isInstalled()) {
echo 'Application is not installed yet, please complete install wizard first.';
exit;
}
Mage::register('custom_entry_point', true);
Mage::$headersSentThrowsException = false;
//Mage::init('admin');
$store_id = Mage::app()->getStore()->getId();
$data = simplexml_load_file("sitemap/sitemap.xml");
$nodes = $data->urlset;
$rewrites = Mage::getModel("core/url_rewrite");
Mage::setIsDeveloperMode(true);
foreach($data as $n):
$url = explode("/", $n->loc );
array_splice($url,0,3);
$url = implode("/", $url);
$coll = $rewrites->getCollection()->addFieldToSelect("*")
->addFieldToFilter("request_path", $url)
->addFieldToFilter("store_id", $store_id )
->setOrder("url_rewrite_id","DESC");
$coll->getSelect()->order("url_rewrite_id",0);
$item_url = $coll->getFirstItem();
unset($coll);
$coll = null;
if(!$item_url)
{
Mage::log("Error loading url rewrite for ".$n->loc,null,"bs_indexhelper.log",true);
continue;
}
$productID = $item_url->getProductId();
$categoryID = $item_url->getCategoryId();
$title = "";
$item = null;
if($productID)
{
$item = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect("name")->addFieldToFilter("entity_id",$productID)->getFirstItem();
$title = $item->getName();
}else if($categoryID){
$item = Mage::getModel("catalog/category")->getCollection()->addAttributeToSelect("name")->addFieldToFilter("entity_id",$categoryID)->getFirstItem();
$title = $item->getName();
}
else
{
Mage::log("Error loading url rewrite for item not found!!! ".$n->loc,null,"bs_indexhelper.log",true);
continue;
}
unset($item);
$item = null;
?>
<a href="<?php echo $n->loc ?>" title="<?php echo $title ?>"><?php echo $title ?></a><br />
<?php
endforeach;
?>
</body>
</html>
Name the file whatever ypu like, the in the webmaster tools fatch ad Google and submit to index with all links..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment