我正在开发一个Laravel应用程序。现在,我正在尝试使用这个包https://github.com/spatie/laravel-sitemap为我的网站实现sitemap。但是当我生成sitemap.xml时,文件中没有包含任何路径。
我安装了运行Composer命令的包
composer require spatie/laravel-sitemap然后我出版了作曲家。
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config在routes/web.php中,我添加了以下内容。
Route::get('sitemap', function () {
SitemapGenerator::create('http://app.localhost/')->writeToFile('sitemap.xml');
return "Sitemap generated".
});当我运行代码并生成sitemap.xml时。当我打开sitemap.xml时,这就是我在里面找到的所有东西。
<?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中有很多路由。哪里出了问题,如何修复它?
发布于 2019-04-10 22:24:00
您可以像下面这样手动添加其他urls,当您运行它时,这些链接将被添加到您的站点地图文件中:
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;
Route::get('sitemap', function () {
SitemapGenerator::create('https://vesicash.com/')->getSitemap()
->add(Url::create('/link1')->setPriority(0.5))
->add(Url::create('/link2')->setPriority(0.5))
->add(Url::create('/link3')->setPriority(0.5))
->add(Url::create('/privacy')->setPriority(0.5))
->writeToFile('sitemap.xml');
return "Sitemap Generated";
});发布于 2020-07-21 19:26:48
这就是我解决这个问题的方法:
我只是确保在.env文件中正确设置了APP_URL。
例如,我补充道:https://example.com/和boom it起作用了。
这也应该适用于您的本地pc。
发布于 2020-03-28 03:37:05
当我第一次这样做的时候,它对我来说看起来是一样的。
<?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>我想你是在你本地的电脑上做的。
因此,首先,您可以使用此url进行测试。
SitemapGenerator::create("https://spatie.be/en")
->writeToFile(public_path('sitemap.xml'));如果它工作得很好,那么我相信它也会在服务器上工作。在我的情况下,它在服务器上工作,而它与您在我的本地上的结果相同。
https://stackoverflow.com/questions/54074213
复制相似问题