使用php创建动态站点地图

问题描述 投票:0回答:2

首先让我告诉你我正在学习php。我想为我的网站创建一个自动动态的站点地图。脚本(假设sitemap.php)将抓取我网站的所有链接,并将创建一个包含1000个网址的数组。一旦1000个URL限制到达,它将使另一个页面id与1000 urls数组。这样脚本输出将如下所示:

<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>

第1页将有xml格式的1000个网址,第2页也将有,这将在网站更新时继续。我已经尝试了来自谷歌的github和其他搜索页面的这么多代码。但还没找到我需要的东西。你能帮忙吗?

php xml sitemap
2个回答
9
投票

一个很好的解决方案是访问你的根文件夹并在.htaccess之后添加到你的apache RewriteEngine On文件中的以下行

RewriteRule ^sitemap\.xml$ sitemap.php [L]

然后只需在根文件夹中有一个文件sitemap.php,因此通常可以通过http://yoursite.com/sitemap.xml访问,sitemap.php是所有搜索引擎首先搜索的默认URL。

文件<?php header('Content-type: application/xml; charset=utf-8') ?> <?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?> 应以...开头,以确保服务器发送正确的HTTP标头:

:Refer

0
投票

这可能会帮助你qazxswpoi

这是CLI脚本。它会自动抓取您的网站,动态生成XML站点地图。

你需要知道以下在脚本上面运行的东西:

  • PHP CLI
  • 卷曲
  • XML

如果您发现任何困难,请检查并告知我们。

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.