我试图为我的网站生成一个站点地图,但我做不到,我的网站使用的是拉拉辛烷。spatie/laravel-sitemap包生成的urls如下所示:
<?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" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://127.0.0.1:8000/</loc>
<lastmod>2022-08-27T00:17:40+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://127.0.0.1:8000/my-url</loc>
<lastmod>2022-08-27T00:17:40+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>它没有设置正确的url域:http://myweb.com/my-url,它正在生成这个http://127.0.0.1:8000/my-url。我使用nginx作为反向代理,请求被重定向到辛烷,正如laravel所说:https://laravel.com/docs/9.x/octane#serving-your-application-via-https。
另外,sitemap是使用一个命令生成的:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\URL;
use Spatie\Sitemap\SitemapGenerator;
class GenerateSitemap extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sitemap:generate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate the sitemap';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
//SitemapGenerator::create(config('app.url'))
SitemapGenerator::create('https://myweb.com')
->writeToFile(public_path('sitemap.xml'));
}
}在调度器中调用该命令:
$schedule->command('sitemap:generate')->daily();我能做什么?谢谢
发布于 2022-08-29 21:39:56
也许这个能帮到你。
namespace App\Console\Commands;
use Illuminate\Http\Request;
use App\Models\Post;
class SitemapController extends Controller {
public function index($value = '') {
$posts = Post::latest()->get();
return response()->view('sitemap', [
'posts' => $posts
])->header('Content-Type', 'text/xml');
}
}https://stackoverflow.com/questions/73533784
复制相似问题