I have three folders with static files (Angular apps): web, login, admin.
I want to serve:
web
folder when the URL is /*
login
when the URL is /admin/*
and not logged admin
when the URL is /admin/*
and logged. My routes.php
:
// admin folder Route::get('/admin', ['before' => 'auth', function() { return File::get(public_path() . '/admin/index.html'); }]); Route::get('/admin/{slug}', ['before' => 'auth', function($slug) { return File::get(public_path() . '/admin/' . $slug); }]); //login folder Route::get('/admin', function() { return File::get(public_path() . '/login/index.html'); }); Route::get('/admin/{slug}', function($slug) { return File::get(public_path() . '/login/' . $slug); }); // web folder Route::get('/', function() { return File::get(public_path() . '/web/index.html'); }); Route::get('/{slug}', function($slug) { return File::get(public_path() . '/web/' . $slug); });
Problems:
/{slug}
doesn't serve files from subfolders. /admin/
redirect me to /login
. How can I solve the previous points?
You've added the same route url 2 times. Laravel standard takes one and skip the other. Therefore the first admin route is taken. Therefore the auth filter is always excecuted. In the standard filter, which is located in the filters.php file, a user which is not logged in is redirected to login. Therefore you're redirected to login. You can solve this by changing the filter or remove the filter and use this for example in you're route:
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]+');
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.