laravel routing返回404而不使用index.php

时间:2017-05-22 12:03:39

标签: laravel-5 routing

我在为网站创建动态sitemap.xml时遇到一个小问题。

我的路由文件:

Route::get('sitemap.xml', [
    'uses' => 'PageController@sitemapXml',
    'as'   => 'user.page.sitemapxml'
]);

我的控制器:

public function sitemapXml(){
        ....
        $content .= '</urlset>';
        return response($content, 200)->header('Content-Type', 'text/xml');
    }

我的问题: 要访问获得正确的响应,我必须使用以下路由: www.mysite.com/index.php/sitemap.xml 但是,如果我执行www.mysite.com/sitemap.xml,我会得到404。 如果我在我的公共文件夹中手动添加sitemap.xml文件,我可以访问刚刚添加的文件,但不能访问在我的控制器中创建的动态文件。

我的研究 它可能是服务器的问题而不是laravel本身。显然,.xml扩展名不会通过正常路由处理。 它建议添加:

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

没有用。

我也尝试将我的.htaccess更改为:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

在文档中指定

我的问题: 他们可以做任何事情来处理.xml请求吗?

另外,如果你可以指导我做任何可以帮助我更好地理解这个过程的事情,那就非常受欢迎了。

提前感谢您抽出宝贵时间提供帮助

更新 如果不使用我的本地主机,我使用&#34; php artisan serve&#34;,一切正常,没有任何问题。

1 个答案:

答案 0 :(得分:0)

我在这个链接上找到了答案: https://laravel.io/forum/09-15-2015-removing-indexphp-from-url-laravel-5116

我改变了我的.conf文件,瞧。

希望这有助于你

只是为了澄清:Laravel没有错。更多服务器特定。