0

Remarkably simple problem I have that I'm not finding a simple solution for.

Essentially I have a duplicate url issue with a Magento site's home page.

I have in the url structure the below:

www.domain.com

but also:

www.domain.com/home

Which essentially point to the same page.

I want to remove the latter url which has /home at the end.

I can't simply disable the CMS page that is the home page, as the home page then loads without the home page content in there.

All I want to do is essentially remove the /home from my sitemap generation and from Google's search index.

I still need the main url www.domain.com to index and be found though.

I'm finding that Google is not indexing my main url properly because of the duplication.

I would have thought there would be a basic setting in Magento admin to prevent this? Thanks for any help as always.

  • Anyone any ideas on an answer for this question? Seems relatively simple in nature but I can't find a simple way to achieve in default core Magento settings :( – MagentoMac Nov 19 '15 at 19:07
2

Move

\app\code\core\Mage\Sitemap\Model\Sitemap.php

to

\app\code\local\Mage\Sitemap\Model\Sitemap.php

Then try adding this code near line 202:

if ($item->getUrl() == 'home/') continue;

It should look similar to this:

...
foreach ($collection as $item) {
        if ($item->getUrl() == 'home/') continue;
        $xml = sprintf(
...
  • Thanks Alldo for the suggestion. I created a custom url 301 rewrite in the meantime which seems to have done the job. Waiting to check that the main homepage comes to the appropriate place in search rankings. if it doesn't, I'll remove it and try your suggestion. It looks fine though. Cheers. – MagentoMac Nov 26 '15 at 10:35
2

How to remove home identifier from the homepage url inside the generated sitemap.

(Tested on CE 1.9.3.4)

  • Before: <loc>http://www.example.com/home</loc>

  • After: <loc>http://www.example.com/</loc>


Copy your Sitemap.php from:

app/code/core/Mage/Sitemap/Model/Sitemap.php

to:

app/code/local/Mage/Sitemap/Model/Sitemap.php

Look for:

foreach ($collection as $item) {

and REPLACE IT with:

$pages = new Varien_Object();
$pages->setItems($collection);
Mage::dispatchEvent('sitemap_cms_pages_generating_before', array(
    'collection' => $pages,
    'store_id' => $storeId
));
foreach ($pages->getItems() as $item) {

then copy Page.php file from:

app/code/core/Mage/Sitemap/Model/Resource/Cms/Page.php

to:

app/code/local/Mage/Sitemap/Model/Resource/Cms/Page.php

and open this too. Look for:

$page = $this->_prepareObject($row);

and REPLACE IT with:

if ($row['url'] == 'home') {
    $row['url'] = '';
}
$page = $this->_prepareObject($row);

Go to the backend, generate a brand new sitemap and Bob's your uncle! :D

  • Is it necessary to add the event in the file Sitemap.php ? Only extending the file Cms/Page.php will do the things ? Please let me know whether I can do this or not ? – Parth Thakkar Jan 23 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.