【发布时间】:2016-07-11 21:10:23
【问题描述】:
我用 laravel 创建了一个动态的 sitemap.xml 路由,它返回一个 xml 响应。
路由在浏览器上运行,但它返回404状态。
这是唯一返回 404 状态的路由
这些是标题:
Cache-Control →no-cache
Connection →keep-alive
Content-Length →232
Content-Type →text/xml; charset=UTF-8
Date →Thu, 24 Mar 2016 09:44:35 GMT
Server →nginx/1.9.12
这是路线:
Route::get('sitemap.xml', ['as' => 'sitemap.index', 'uses' => 'SitemapController@index']);
这是控制器响应:
$response = response()->view('sitemaps.index', [
'last' => $data,
'modules' => $modules,
'app' => $app,
])->header('Content-Type', 'text/xml');
$response->header('Content-Length',strlen($response->getOriginalContent()));
return $response;
观点:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@foreach($modules as $module)
<sitemap>
<loc>{{ url('sitemap-' . $module . '.xml') }}</loc>
<lastmod>{{ $last[$module]['updated_at'] or date('Y').'-01-01'}}</lastmod>
</sitemap>
@endforeach
谢谢。
【问题讨论】:
标签: php xml laravel nginx http-status-code-404