Magento2 sitemap

基于 Magento2 自带的 Sitemap 模块进行处理。

一、Sitemap 的相关配置项

进入 Magento 后台,在侧边栏点击 Stores > Settings > Configuration > CATALOG > XML Sitemap ,可以看到分类、商品、Page 等相关选项。

1、Categories Options / CMS Pages Options / Store Url Options

相关配置项解析如下:

  • Frequency : 确定 sitemap 分类、商品、CMS 页等的更新频率
  • Priority : 一个介于 0.0 和 1.0 之间的值,用于确定 Store URL 更新相对于其他内容的优先级。零 (0.0) 的优先级最低。

Magento2 sitemap

Magento2 sitemap

2、 Products Options

  • Add Images into Sitemap : 确定图像包含在 sitemap 中的范围。推荐:Base Only。

Magento2 sitemap

3、Generation Settings

  • Enabled : 确定 XML 格式的 sitemap 是否可用于 store

  • Start Time : 指定更新 sitemap 的时间,一天中的小时、分钟和秒。

  • Error Email Recipient : 在 sitemap 更新过程中发生错误时,收到通知人员的电子邮件地址。多个地址请用逗号(,)分隔每个地址。

  • Error Email Sender : sitemap 更新失败时,发送错误通知邮件的发件人。此下拉选项的配置位置在 Stores > Settings > Configuration > GENERAL > Store Email Addresses
    Magento2 sitemap

  • Error Email Template : sitemap 更新失败时,发送错误通知邮件的电子邮件模板。

Magento2 sitemap

4、Sitemap File Limits

  • Maximum No of URLs Per File : 确定单个 sitemap 文件可以包含的最大网址数。
  • Maximum File Size : 确定生成的 sitemap 文件的最大大小(以字节为单位)

不同的搜索引擎可能有不同的规则和限制。Google XML sitemap 不应超过 50,000 个网址,并且不应大于 50MB(52,428,800 字节) 这些规则也适用于 Magento 2。

Magento2 sitemap

5、 Search Engine Submission Settings

  • Enable Submission to Robots.txt : 允许为 Robots.txt 文件提交指令。

Magento2 sitemap

二、生成 sitemap.xml 文件

进入 Magento 后台,在侧边栏点击 MARKETING > SEO & Search > Site Map,点击 Add Sitemap,配置文件名、生成位置等信息,结果如下图:
Magento2 sitemap

三、配置 crontab

需要将 php bin/magento cron:run 配置到 crontab 中。在命令行输入 crontab -e 进入编辑,输入

#~ MAGENTO START
* * * * * /usr/bin/php /Users/project/magentoce2.4.3/bin/magento cron:run  >> /Users/project/magentoce2.4.3/var/log/cron.log

在数据表 cron_schedule 中会看到运行的脚本信息。运行完脚本之后会发现 /Users/project/practise/magentoce2.4.3/pub/sitemap.xml 文件更新了。cron 脚本运行前
Magento2 sitemap

cron 脚本运行后
Magento2 sitemap

其他方案

咨询了其他项目的开发,他们没有使用 Magento 自带的 sitemap 模块,而是使用前后端相结合的方式来处理。后端创建新的数据表,存储需要抓取的链接信息;写一个自动脚本每个周定时更新链接信息【先清空后插入】;再通过 API 将数据表中的链接提供给前端。前端对链接信息进行处理。

本作品采用《CC 协议》,转载必须注明作者和本文链接
May
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!