手册:generateSitemap.php
MediaWiki文件: generateSitemap.php | |
---|---|
位置: | maintenance/ |
源代码: | master • 1.35.2 • 1.31.14 |
类: | GenerateSitemap |
详情
generateSitemap.php文件是一个维护脚本,用于为一个安装好的MediaWiki生成sitemap。Sitemap是一个用于让搜索引擎爬虫(如Google爬虫)更有效率地索引一个网站的文件(前提是爬虫支持sitemap协议)。
本脚本会默认生成一个sitemap索引文件,以及一个包含所有有内容的命名空间的通过gzip压缩后的sitemap。在#Options节查看可以被传递给本脚本的选项。
此外,你可能会需要创建一个定时任务来自动更新sitemap。
如果你还需要关于MediaWiki的维护脚本(maintenance scripts)的通用介绍,你可以在这里查看更多:手册:维护脚本 。
选项
--help
- 查看可以用于
generateSitemap.php
的选项。
--fspath=<path>
- 生成的sitemap在文件系统上的路径。示例:
sitemap/
。注意,这个文件夹必须是对访客可见的。
--identifier=<identifier>
- 维基的站点标识符,默认为$wgDBname 。
--urlpath=<prefix>
- 指向
--fspath
相對於域名的URL,如:- /sitemap/
- 如果指定了本选项,则可以在被sitemap索引的文件中生成前缀。这个选项是必要的,因为一些搜索引擎(如Google)需要sitemap提供的URL使用绝对路径。如果使用了本选项,你也应该同时指定
--server
。这两者的值通常是相似的,但将它们分开处理可以让脚本在一些不寻常的设置下正常工作。 - Before MediaWiki 1.32.0 this parameter should contain the protocol and host name. However, since MediaWiki 1.32.0 the contents of this parameter will be appended to the
--server
parameter, thus it must neither contain protocol nor hostname. This is a breaking change not announced via the RELEASE-NOTES.
--server=<server>
- 在URL中使用的协议和主机名字,如:
- 有时设置这个是很有必要的,因为在命令行脚本中检测服务器名字不一定会成功,那会导致生成的xml文件会把"localhost"或"my.servername"作为主机名字。
- If set the value of
$wgCanonicalServer
will override the value of this option in all sitemap files except for the sitemap index file.
--compress=[yes|no]
- 用于决定是否对sitemap文件进行压缩。默认为
yes
。
--skip-redirects
- 如果命令中附带了本选项,则重定向页面不会被生成到sitemap中。 我们推荐使用本选项,因为Google反感过多的重定向。 虽然推荐使用,但我们默认仍然是"不"略过生成重定向页面链接。
例子
为Google站长工具创建网站地图:
首先(对于$IP,文档根目录就是你的“LocalSettings.php”文件所在的位置):
mkdir sitemap
然后:
MediaWiki版本: | ≥ 1.32 |
php maintenance/generateSitemap.php --memory-limit=50M --fspath=/path/to/examplecom/sitemap/ --identifier=examplecom --urlpath=/sitemap/ --server=https://www.example.com --compress=yes
非拉丁文字域名需要使用国际化域名编码。
相關配置变量
MediaWiki版本: | ≥ 1.13 |
$wgSitemapNamespaces
: 需要生成Google sitemap的命名空间的数组,如果要为所有命名空间生成,则设置为false。默认值是false
。
MediaWiki版本: | ≥ 1.19 |
$wgSitemapNamespacesPriorities
: 为sitemap设置命名空间的优先级。这里应该是一个 命名空间 到 优先级 的 map,默认为false
。