简体   繁体   English

Laravel 5路由所有路由

[英]Laravel 5 Routing ALL routes

I am new to laravel, and im trying to get redirect all incoming requests from /example to exampleController@index I am using this route 我是laravel的新手,我试图将所有来自/example传入请求重定向到exampleController exampleController@index我正在使用这条路由

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

Everything works fine with /example/any/any/any , but I am getting No input file specified. 使用/example/any/any/any一切正常,但是我收到了No input file specified. error when i try /example/any/any/any.php Please help me to solve this problem. 我尝试/example/any/any/any.php时出错请帮我解决这个问题。 Thanks. 谢谢。

Route::match is only used to match multiple HTTP Verbs to a route. Route::match仅用于将多个HTTP Verbs与路由匹配。

As far as I know you can't achieve what you want, and there is no point to do this. 据我所知,你无法达到你想要的效果,没有必要这样做。

What you may need is Route::resource check the docs 您可能需要的是Route::resource检查文档

Managed to get it working by editing NGINX config file. 通过编辑NGINX配置文件来管理它。 In my situation im using laravel 5 homestead with default configuration. 在我的情况下我使用laravel 5宅基地默认配置。 Config file is located /etc/nginx/sites-enabled/homestead.app . 配置文件位于/etc/nginx/sites-enabled/homestead.app Add try_files $uri $uri/ /index.php?$args; 添加try_files $uri $uri/ /index.php?$args; right after location ~ \\.php$ . location ~ \\.php$之后location ~ \\.php$ Should look similar to this 应该看起来与此类似

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

I am not sure as to why, but you can use Route::group with a prefix as such 我不确定为什么,但你可以使用带有前缀的Route :: group

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

Going to http://yoursite.com/example/action/111 will use the getAction method in the ExampleController. 转到http://yoursite.com/example/action/111将使用ExampleController中的getAction方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM