Reputation: 1892
i have a simple news website, where my news articles are stored in a database
im trying to make a (dynamic) sitemap.xml using php but its the first time and have a few questions i cant find the answers to anywhere
so firstly, do i save it as Sitemap.php file at the root, and then use htaccess to point sitemap.xml to sitemap.php? or instead, do i get the php script to create, using fwrite, a new sitemap.xml file?
ive seen both approaches recommended on various sites.
secondly, do i just echo out all the xml stuff in php?
thanks
Upvotes: 0
Views: 168
Reputation: 197757
so firstly, do i save it as Sitemap.php file at the root, and then use htaccess to point sitemap.xml to sitemap.php?
Yes, you can do so, however, you will get a 404 error. So I don't suggest you to do that with a file-system that is case-sensitive (a POSIX one for example).
Instead, save it as sitemap.php, not Sitemap.php.
or instead, do i get the php script to create, using fwrite, a new sitemap.xml file?
Yes, you can do so. This will reduce the load on your server so generally recommended. You can additionally already gzip the file and serve it compressed to reduce bandwidth.
ive seen both approaches recommended on various sites.
you've seen right.
secondly, do i just echo out all the xml stuff in php?
That depends on your taste. I personally would not do it that way but use an XML library that is able to stream to a filename which could be even php://output
.
Upvotes: 1