【问题标题】:Laravel 5 Routing ALL routesLaravel 5 路由所有路由
【发布时间】:2016-08-01 13:16:49
【问题描述】:

我是 laravel 新手,我正在尝试将所有传入请求从 /example 重定向到 exampleController@index 我正在使用这条路线

 Route::match(['get', 'post'], '/example/{any}', ['uses' =>'exampleController@index'])->where('any', '.*');

/example/any/any/any 一切正常,但是当我尝试/example/any/any/any.php 时出现No input file specified. 错误,请帮我解决这个问题。谢谢。

【问题讨论】:

  • NGIX 会将对 .php 文件的请求转发给 PHP 文件处理程序,而不检查文件是否存在。在 apache 中,这通常是使用 mod_rewrite 解决的,我猜 NGIX 也有类似的东西。检查nginxlibrary.com/resolving-no-input-file-specified-error
  • 嗨,感谢您的评论,我设法通过更改 NGINX 配置来做我想做的事。只需添加此try_files $uri $uri/ /index.php?$args; 现在它可以按预期工作。
  • 如果您用解决方案回答了自己的问题,它可能会对其他人有所帮助。

标签: php nginx laravel-5 routing frameworks


【解决方案1】:

Route::match 仅用于将多个HTTP Verbs 匹配到一个路由。

据我所知,你无法实现你想要的,这样做没有意义。

您可能需要Route::resource 查看文档

【讨论】:

    【解决方案2】:

    通过编辑 NGINX 配置文件使其正常工作。在我的情况下,我使用默认配置的 laravel 5 homestead。配置文件位于/etc/nginx/sites-enabled/homestead.app。在location ~ \.php$ 之后添加try_files $uri $uri/ /index.php?$args;。应该和这个类似

    location ~ \.php$ {
            try_files  $uri $uri/ /index.php?$args;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            ....
        }
    

    【讨论】:

      【解决方案3】:

      我不确定为什么,但是您可以使用带有前缀的 Route::group

      Route::group(['prefix' => 'example'], function() {
          Route::get('action/{id}', 'ExampleController@getAction');
      });
      

      转到http://yoursite.com/example/action/111 将使用 ExampleController 中的 getAction 方法。

      public function getAction($id) {
          // do something with Example with this $id
      }
      

      【讨论】:

      • 我正在开发“智能”代理服务器,所以我希望所有对application.com/proxy/{method}/{method}?{parameters} 的传入请求都使用相同的方法ProxyController@index。无论如何.. 扩展问题已修复,感谢 cmets。干杯
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 2017-05-22
      • 2017-10-02
      • 2016-07-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多