# Get all Magento URLs by store view

I'm looking to retrieve all URLs of a Magento website (CMS pages, categories, products...) subdivided by store view. Something like the default Magento Sitemap, but with a different format: specifically I'm trying to get a "one URL per row" plain text file, one for each store view.

Take a look at how Magento generates it's sitemap.xml file.

Specifically the Mage_Sitemap_Model_Sitemap class method generateXml. For example, following snippet generates them for the categories, I've rewritten it a little to export to a flat text file.

$ioWrite = new Varien_Io_File();$path = '';
$ioWrite->open(array('path' =>$path));
$ioWrite->streamOpen($path.'urls.txt');

$storeId = Mage::app()->getStore()->getId();$date    = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);

/**
* Generate categories sitemap
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/category/changefreq',$storeId);
$priority = (string)Mage::getStoreConfig('sitemap/category/priority',$storeId);
$collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
$categories = new Varien_Object();$categories->setItems($collection); Mage::dispatchEvent('sitemap_categories_generating_before', array( 'collection' =>$categories
));
foreach ($categories->getItems() as$item) {
$ioWrite->streamWrite(htmlspecialchars($baseUrl . $item->getUrl())); } unset($collection);
\$ioWrite->close();


Add the code from the class to your own script to generate a text file

• Thanks @Sander for the hints, I've got a solution starting from this. – Riccardo Nov 11 '15 at 13:03

Thanks to @sander-mangel I've developed a solution for my specific case: https://gist.github.com/RiccardoB/2117046a97719b413c8a

If you have any optimization/fix to suggest, feel free to comment.