我有三个包含静态文件(Angular应用程序)的文件夹:web、login和admin。
我想服务:
- URL为
/*
时的web
文件夹 - 当URL为
/admin/*
且未记录时为login
- 当URL为
/admin/*
并且已记录时为admin
我的routes.php
:
//管理文件夹路由::get('/admin',['before'=>'auth',function(){return File::get(public_path().'/admin/index.html');}]);路由::get('/admin/{slug}',['before'=>'auth',function($slug){return File::get(public_path().'/admin/'$段塞);}]);//登录文件夹路由::get('/admin',function(){return File::get(public_path().'/login/index.html');});路由::get('/admin/{slug}',function($slug){return File::get(public_path().'/login/'$段塞);});//web文件夹路由::get('/',function(){return File::get(public_path().'/web/index.html');});路由::get('/{slug}',function($slug){return File::get(public_path().'/web/'$段塞);});
问题:
/{slug}
不提供子文件夹中的文件- 当我没有登录时,
/admin/
会将我重定向到/login
- 必须有一种用正则表达式编写此路由的方法
如何解决前面的问题?
- 不知道你的第一点是什么问题。可能的问题:
- 您输入一个扩展名为slug,例如slug.html。在这种情况下,标准的laravel-htaccess会尝试搜索一个不存在的文件。所以拉拉威尔没有被解雇!为了解决这个问题,你可以更改htaccess或者在你的路由中不使用扩展
-
你已经添加了两次相同的路由url。拉拉威尔标准取一个,跳过另一个。因此,采取了第一条管理路线。因此,身份验证过滤器总是被优化的。在filters.php文件中的标准筛选器中,未登录的用户将重定向到登录。因此,您被重定向到登录。你可以通过更改过滤器或删除过滤器来解决这个问题,例如在你的路线中使用:
Route::get('/admin',function() { if(Auth::check()) return File::get(public_path() . '/admin/index.html'); return File::get(public_path() . '/login/index.html'); }); Route::get('/admin/{slug}',function($slug) { if(Auth::check()) return File::get(public_path() . '/admin/' . $slug); return File::get(public_path() . '/login/' . $slug); });
- 正如你在这里看到的,你可以使用正则表达式。例如
->where('slug', '[A-Za-z]+');
希望这能有所帮助!