The function AdminMetaController::generateRobotsFile() is responsible for generating the robots.txt file in Prestashop. This function is executed via PREFERENCES -> SEO & URLS -> Generate robots.txt file.
But in one of our projects we faced the following issue: the sitemap.xml file is generated by the default Gsitemap module, which saves the file under the name {shop_id}_index_sitemap.xml. But the function AdminMetaController::generateRobotsFile() uses the following code to find sitemap:
1 2 3 4 5 6 |
// Sitemap if (file_exists($this->sm_file) && filesize($this->sm_file)) { fwrite($write_fd, "# Sitemap\n"); fwrite($write_fd, 'Sitemap: '.(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$_SERVER['SERVER_NAME'].__PS_BASE_URI__.'sitemap.xml'."\n"); } |
This means that the function is checking exactly for the file with the name sitemap.xml and includes it into robots.txt. But our file has a different name (1_index_sitemap.xml), that is why search engines are not able to find it.
To fix this, we created override/controllers/admin/AdminMetaController.php of the function generateRobotsFile():
1 2 3 4 5 6 7 8 |
/* override reason */ if (file_exists(_PS_ROOT_DIR_ . '/' . $this->context->shop->id . '_index_sitemap.xml')) { fwrite($write_fd, "# Sitemap\n"); fwrite($write_fd, 'Sitemap: '.(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').Tools::getShopDomain(false, true).__PS_BASE_URI__.$this->context->shop->id.'_index_sitemap.xml'."\n"); } elseif (file_exists($this->sm_file) && filesize($this->sm_file)) { //default logic fwrite($write_fd, "# Sitemap\n"); fwrite($write_fd, 'Sitemap: '.(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$_SERVER['SERVER_NAME'].__PS_BASE_URI__.'sitemap.xml'."\n"); } |
This way Prestashop will be able to find and work with the sitemap file.
For Prestashop modules please check this page: https://store.belvg.com/extensions/prestashop.html
Hello;
not is more easy rename the file, from the server?
I cannot find AdminMetaController.php under override/controllers/admin. In the folder admin only got index.php and templates. What should i do? My google webmaster tool only show 1 index page. How i can solve this?
Jose,
But they are really trying to fix them:)
Hi Alex,
Thanks for the post. Very usefull.
Honestly, i don’t understand at all how can Prestashop have this kind of errors.
Dean Dolić,
I saw this bug only in Prestashop 1.6, but if you have similar problems in other versions you can try this method.
Hi,
I’m not sure, but is this bug present in all major PS releases including 1.6?
We have our store still on 1.5.4.1 so I wonder if I should apply this fix?