首页 > 解决方案 > url传入参数的搜索结果页面返回状态404

问题描述

尝试使用以下形式在我的 laravel 网站上实现简单的搜索:

<form action="https://www.example.com/search-results" class="cse-search-box"> 
    <input type="hidden" name="cx" value="partner-pub-mygoogleid:myid"> 
    <input type="hidden" name="cof" value="FORID:10"> 
    <input type="hidden" name="ie" value="UTF-8"> 
    <input type="text" class="search-inp icon" name="q" size="30" placeholder="Search my site"> 
</form>

此表单生成的 url 是:

https://www.examlle.com/search-results?cx=partner-pub-mygoogleid%myid&cof=FORID%3A10&ie=UTF-8&q=searchterm`

我的路线是:

Route::get('search-results', 'SearchController@getResults');

除了一件非常有趣的事情外,一切似乎都有效,搜索结果页面显示状态 404。

当我从 url 中删除参数时,状态变为 200。

知道为什么会发生这种情况,或者有任何建议如何实现此表单,以便在存在参数时其响应为 200?

标签: phplaravel

解决方案


我发现我的问题nginx.conf

问题在于这一行的位置 php 块内try_files $query_string/index.php =404;

location ~ \.php$ {
    # try_files $query_string/index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

status 404将其注释掉后,一切都按预期工作,我的搜索结果页面上不再有


推荐阅读