Spatie Laravel Sitemap生成的xml文件为空 [英] Spatie Laravel sitemap generated xml file is empty

查看:129
本文介绍了Spatie Laravel Sitemap生成的xml文件为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Laravel应用程序.现在,我正在尝试使用此软件包 https://github.com/为我的网站实施站点地图spatie/laravel-sitemap .但是当我生成sitemap.xml时,文件中没有路径.

I am developing a Laravel application. Now, I am trying to implement the sitemap for my website using this package, https://github.com/spatie/laravel-sitemap. But when I generate sitemap.xml, no paths are included in the file.

我安装了运行Composer命令的软件包

I installed the package running the Composer command

composer require spatie/laravel-sitemap

然后我发布了作曲家.

php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config

在routes/web.php中,我添加了它.

In the routes/web.php, I added this.

Route::get('sitemap', function () {
    SitemapGenerator::create('http://app.localhost/')->writeToFile('sitemap.xml');
    return "Sitemap generated".
});

当我运行代码并生成sitemap.xml时.当我打开sitemap.xml时,便可以在其中找到所有内容.

When I run the code and sitemap.xml is generated. When I opened the sitemap.xml, that is all I found in it.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>

我在web.php中有很多路由.有什么问题,如何解决?

I have many routes in the web.php. What is wrong and how can fix it?

推荐答案

当我第一次这样做时,它对我来说看起来是一样的.

When I did it first time it looked same for me.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>

我认为您是在本地PC上完成的.

I think you did it on your local pc.

因此,首先,您可以使用此URL进行测试.

So first, you can test with this url.

SitemapGenerator::create("https://spatie.be/en")
            ->writeToFile(public_path('sitemap.xml'));

如果运行良好,那么我相信它也可以在服务器上运行. 就我而言,它可以在服务器上运行,而与您在本地服务器上的结果相同.

If it works well, then I believe it will work on server too. In my case it worked on server, while it was same result with you on my local.

这篇关于Spatie Laravel Sitemap生成的xml文件为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆