如何为php网站生成XML站点地图
从现在开始,我们的网站使用了 WordPress,并且使用一些插件可以很容易地为整个网站创建 xml 站点地图。 现在我们正在切换到从头开始创建的 php 网站,经过一些谷歌搜索后,我没有找到可以帮助我理解如何为我的网站创建站点地图的内容。
请有人帮忙,使用任何一种软件或任何网络脚本吗?
谢谢。
Since now we have used wordpress for our website, and the xml sitemap was very easy to create for the whole website with some plugins.
Now we are switching to a php website created from scratch, after some google search i haven't found something to help me to understand how can i create a sitemap for my website .
Please can some one help, with any kind of software or any web script?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上取决于您提供页面的方式(来自数据库、包含文件、您拥有的内容),但是,如果您没有很多页面,您可以简单地创建一个名为
sitemap.xml
手动将其放在根目录中。您可以通过快速谷歌搜索来模拟大量示例。It really depends on how you have the pages served (from database, include files, what-have-you) but, if you don't have very many pages you could simply create a document called
sitemap.xml
by hand and place it in your root directory. There are droves of examples you could emulate from a quick google search.要创建 sitemap.xml,请阅读 sitemap.xml 格式,然后创建一个 XML 文件符合该格式。
如何做到这一点?嗯,这取决于您网站的结构。也许您可以手工编写它,也许您可以根据数据库中的内容生成它,也许您可以抓取您的网站,也许您可以......?这个问题实际上没有具体的答案——这完全取决于您的网站的组织方式。
To create a sitemap.xml, read up on sitemap.xml format, then create an XML file that conforms to that format.
How to do this? Well, that depends on the structure of your site. Maybe you could write it by hand, maybe you could generate it based on stuff in the database, maybe you could crawl your site, maybe you could...? This question doesn't really have a specific answer--it all depends on how your site is organized.
如果数据库中有页面列表,则可以使用它。几乎所有网站都具有静态页面目录、包含页面的数据库或两者的组合。您应该能够生成所有页面的列表。如果您可以将它们放入数组中,那么也可以将它们放入 XML 中。使用 PHP 的 SimpleXML 扩展。这很简单。 :)
如果您无法以这种方式生成导出,您可以使用某种爬虫程序来生成在爬行您的主页和域中所有后续页面时找到的 URL 列表。
If you have a list of pages in a database, you can use that. Almost all websites have either a directory of static pages, a database with pages, or a combination of both. You should be able to generate a list of all your pages. If you can put them in an array, you can put them in XML as well. Use the SimpleXML extension from PHP. It is, well, Simple. :)
If you cannot generate an export this way, you could use some kind of crawler to generate a list of urls that are found when crawling your main page and all successive pages in your domain.