Route::get('hello',function(){
     return 'Hello World!';
});

在laravel/app/Http/routes.php下添加上面的语句,然后再浏览器中使用localhost/laravel/public/hello,用Apache来运行,会报404错误,后来在网上查了资料,发现是URL重定向的问题,具体的解决方法如下:

1,php开启phpopenssl

2,在apache conf开启rewrite莫块
模块(#LoadModule rewrite_module modules/mod_rewrite.so)

3,在conf文件中找到directory 把AllowOverride None 改成 AllowOverride All

<Directory>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
4,在laravel项目工程的public目录下添加.htaccess文件 ,文件内容如下

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On

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

5、restart以下Apache服务器就没问题了。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-10-15
  • 2021-06-23
  • 2021-06-05
猜你喜欢
  • 2022-01-18
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案