When I was learning about XML sitemaps, I learned that the number one guideline states that “Google will crawl URLs exactly as listed” in the sitemap. But in 2010, while I was working on one of the first Magento sites I was able to install myself, I saw that the sitemap it generates contains a homepage URL with an added “
/home” at the back. Something like this:
That created a problem for me because I knew I need the correct homepage URL in my XML sitemap when I submit it to Google Webmaster Tools (now Google Search Console) and Bing Webmaster Tools.
I found out that I can copy a Magento core file into the
/app/code/local/ folder and Magento will use whatever changes I put in that file. And, also my changes will be immune to future Magento upgrades if I put them under the local folder. So, I tried that approach to solve my problem.
I enumerated for you below the steps I have taken.
- Using FTP, I opened
/app/code/core/Mage/and found the
- From that folder, I downloaded the
/Model/Sitemap.phpfile to my computer then opened it with my favorite html editor. (You can use Notepad, Notepad++, Dreamweaver, etc.)
- Within that file, I found this line of code which I still see in Magento 220.127.116.11:
- I replaced it with this code:
str_replace is a standard PHP function.
- Then, I uploaded the updated Sitemap.php file to
/app/code/local/Mage/Sitemap/Model/folder. (If you have a fresh Magento install you will have to create the
/app/code/local/folder where you can add the
- Next, I logged into Magento admin and went to Catalog => Google Sitemap to regenerate my sitemap. (Please see Video 1 below If you haven’t generated a sitemap via the Magento backend before.)
- This next step is very important. I made sure I reindexed Magento via System => Index Management and cleared the Magento Cache in System=>Cache Management. (See Video 2 and Video 3 below to learn how to safely do these two things)
- After that, I refreshed the sitemap I was viewing in my web browser, e.g.
http://example.com/sitemap.xmland saw that the
http://example.com/homeURL is replaced by
http://example.com/which is exactly what I want submitted with my XML sitemap.
If you are going to try this same solution, please do it first on a staging environment. Never attempt anything on a production site even if you are 100% sure it will work okay. And, most important of all, backup your Magento files and database before starting work on them.
I hope what I’ve shared with you in this post helps. Thank you for taking the time to read. I invite you to leave a comment or suggest any other solution for this same topic. Lastly, please don’t forget to subscribe to my blog.