Front-end - Routing issues encountered when developing with laravel
大家讲道理
大家讲道理 2017-05-16 16:50:56
0
1
524

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?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
仅有的幸福

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:

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

The original meaning is : If it is not a directory!-d, nor a file!-f, then parse to index.php

was modified to

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!