We are developing using laravel. The static resource directory and routing in the project will have the same name, such as:
//web的静态资源路径
/public/web/xxx
//定义的路由
Route::group(['prefix' => 'web'], function () {
Route::get('/', 'XxxController@indexPage');
});
If configured in this way, a 404 error will occur when using the PHP built-in server to access localhost:8000/web in the development environment:
The requested resource /web_dealer was not found on this server.
After some research, it seems that it is because there is a resource path with the same name in the public directory, so the server has no way to handle it and processes it directly as a static resource. But in fact, this web is just a folder, so the above 404 appears.
Use apche server for testing. Apache seems to redirect (301) localhost:8000/web to localhost:8000/web/, and the directory structure will be exposed on the page. Setting options -Indexes only disables display, but localhost:8000/web will still be redirected.
I would like to know how to configure it if you want to unify the static resource path and route naming as shown above. Or is there any other better naming scheme?
This can be achieved by modifying public/.htaccess (LAMP local test passed under Linux Mint)
Steps
Modify the .htaccess file in the public directory
Locate:
The original meaning is : If it is not a directory!-d, nor a file!-f, then parse to index.php
was modified to
now means : if it is not a file !-f, then parse to index.php
(in a sense !-d is no longer useful)
The local test passed. It is currently unknown whether it will cause other problems.