laravel在子目录中,但路由指向父目录

时间:2017-07-04 15:43:15

标签: laravel routes lighttpd subdirectory

我在laravel路线有问题,我不知道如何解决它!

首先,我应该说我的网络服务器是lighttpd,如果你想说使用另一个网络服务器,就没办法将它改为nginx或apache ......:D

好吧,我的项目位于“/ path / to / some-where / htdocs”,我的域名是“example.com”

在“lighttpd.conf”中我将“example.com”指向“/ path / to / some-where / htdocs / public /”,一切运行良好,laravel工作正常,但由于某些原因,我做了一些变化导致我们需要“example.com”域用于其他一些项目

我将项目移动到“foo”子目录,所以现在我的项目路径是“/ path / to / some-where / htdocs / foo /”,并且我在lighttpd中进行了一些更改,并将“example.com/foo”指向“/路径/到/一些-其中/ htdocs中/富/公共/”

我也将.env中的APP_URI更改为“http://example.com/foo” 但当我打开“example.com/foo”时,它显示“路径未找到”错误,laravel它正在工作,但它不识别“/ foo”作为基本目录,当我将所有路由放入路由组中时“ foo“前缀工作正常!

用于测试我做了这些路线

    Route::get("/", function(}{return "sweet home!";));
    Route::get("/{slug}", function($slug}{return $slug;));

当我打开“example.com/foo”它应该显示我“甜蜜的家”但相反,它显示我“foo”因为我说laravel不认识“foo”作为基本目录 看来我应该改变基础目录或项目的基础uri,但我找不到任何东西

正如我所说,我改变了APP_URI,而且我也放了

    RewriteBase /foo/

在.htacess但没有结果!

1 个答案:

答案 0 :(得分:0)

您应该以这种方式为路线添加前缀:

Route::group(['prefix' => 'foo'], function() {
   Route::get("/", function(}{return "sweet home!";));
   Route::get("/{slug}", function($slug}{return $slug;));
});