laravel 路由404

学习laravel的时候 再web.php写 路由的时候 一直404

  

Route::get('art', function(){
   return 'hello laravel 7';
});

 

解决方法:

1.在apache conf开启rewrite模块,把下面这句话前面的#去掉。

LoadModule rewrite_module modules/mod_rewrite.so

2.在conf文件中找到directory 把AllowOverride None 改成 AllowOverride All

<Directory "c:/Apache24/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

3.在laravel项目工程的public目录下添加.htaccess文件 ,文件内容如下

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

然后重新apache服务重新访问就可以运行了。

posted @ 2021-10-20 17:39  79524795  阅读(105)  评论(0编辑  收藏  举报