【问题标题】:Search results page with parameters passed in url returns status 404url传入参数的搜索结果页面返回状态404
【发布时间】:2020-07-08 17:18:10
【问题描述】:

尝试使用以下表单在我的 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?

【问题讨论】:

  • 也许,您的 id 拼写错误。如果一个不存在的 id 进来,页面通常会返回 404 作为错误代码,让你知道这样的 id 不存在。
  • examlle.com/search-results?param=value的get请求的http状态是什么
  • @Kurt,http状态码是404,但页面实际上在浏览器中显示正确
  • @AlexB 这更奇怪。您可能需要在这里进行一些手动调试/xdebugging。 :( 希望其他人可以为您解决。
  • @STA,会试一试。会在这里发回

标签: php laravel


【解决方案1】:

我在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

【讨论】:

    猜你喜欢
    • 2013-08-28
    • 2011-11-22
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    相关资源
    最近更新 更多