Laravel 路线有效,但 returns 404 状态

Laravel route works, but returns 404 status

我用 laravel 创建了一个动态 sitemap.xml 路由,returns 一个 xml 响应。

路由 在浏览器上工作,但它 returns 一个 404 状态

这是唯一returns 404 状态的路由

这些是headers:

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

谢谢。

这是一个 Nginx 问题。

我在配置文件中添加了这段代码,现在可以使用了:

location = /sitemap.xml {
    try_files $uri $uri/ /index.php?$query_string;
    access_log off;
    log_not_found off;
}

然后我从响应中删除了 <?xml version="1.0" encoding="UTF-8"?>