【问题标题】:Laravel sitemap generator output empty fileLaravel 站点地图生成器输出空文件
【发布时间】:2020-04-09 15:27:23
【问题描述】:

我已经安装了一个新的 Laravel (v 6.7) 项目,然后安装了这个包 spatie/laravel-sitemap。因此,就像在文档中一样,我已将以下代码添加到我的路由文件 web.php 文件中

use Spatie\Sitemap\SitemapGenerator;

Route::get('/sitemap', function () {
ini_set('max_execution_time', 300); // 5 minutes
SitemapGenerator::create('http://sandrianaplantations.com/')->writeToFile('sitemap.xml');
return 'completed';
});

然后当我检查 sitemap.xml 文件时,它的内容如下

    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://sandrianaplantations.com/</loc>
<lastmod>2019-12-17T06:35:43+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>

但如果我通过XML-sitemap.com 为上面的 url 生成站点地图,它会生成下面的内容

  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!--
 created with Free Online Sitemap Generator www.xml-sitemaps.com 
-->
<url>
<loc>https://sandrianaplantations.com/</loc>
<lastmod>2019-12-17T06:33:44+00:00</lastmod>
<priority>1.00</priority>
</url>
<url>
<loc>https://sandrianaplantations.com/About-us/</loc>
<lastmod>2019-12-17T06:33:44+00:00</lastmod>
<priority>0.80</priority>
</url>
<url>
<loc>https://sandrianaplantations.com/Gallery/</loc>
<lastmod>2019-12-17T06:33:44+00:00</lastmod>
<priority>0.80</priority>
</url>
<url>
<loc>https://sandrianaplantations.com/Contacts/</loc>
<lastmod>2019-12-17T06:33:44+00:00</lastmod>
<priority>0.80</priority>
</url>
</urlset>

所以任何人都可以告诉我我是否在我的路线文件中犯了任何错误。(web.php)。我已经阅读了那里的官方文件。但是什么也找不到。也通过YouTube。也几乎检查了以下问题。

question 01

question 02

【问题讨论】:

    标签: php xml laravel laravel-sitemap


    【解决方案1】:

    注意:这个包生成其他站点而不是自己的站点! 但是在doc包中有一个技巧

    spatie/laravel-站点地图 配置爬虫 爬虫本身可以配置为做一些不同的事情。

    【讨论】:

    • 嘿@Sajjad 我不认为这与路径有关。我也对此进行了测试。没有任何改变
    • 操作我安装了这个包并且有同样的问题!!!但是“sandrianaplantations.com”改变其他网站的工作!我猜不是自我爬取并生成站点地图
    • 更改了网址并检查了错误日志。但还是一样
    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2014-06-11
    • 1970-01-01
    • 2020-05-22
    相关资源
    最近更新 更多