First let me tell you I am learning php. I want to create an automatically dynamic sitemap for my site. The script (suppose sitemap.php) will crawl all the links of my site and will create an array of 1000 urls. Once 1000 urls limit reaches, it will make an another page id with 1000 urls array. So that the script output will be like this :
<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/siteindex.xsd">
<sitemap>
<loc>http://exmaple.com/sitemap.php?page=1</loc>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap.php?page=2</loc>
</sitemap>
</sitemapindex>
Page 1 will have 1000 urls in xml format and page 2 will have also and this will go on as the site is updated.I have tried so many codes from github and other seach pages from google. But have not found exactly what I need. Can you help please.
A good solution is to have access to you root folder and add to your apache .htaccess file the following line after RewriteEngine On
RewriteRule ^sitemap\.xml$ sitemap.php [L]
and then simply having a file sitemap.php in your root folder that therefore would be normally accessible via http://yoursite.com/sitemap.xml, the default URL where all search engines will firstly search.
The file sitemap.php shall start with, to make sure that the server sends the correct HTTP header:
<?php header('Content-type: application/xml; charset=utf-8') ?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With