Laravel5.5のルーティングでルート以外全部Not Found
VagrantでCentOS7の環境を新しく作って、
PHPやらApacheやらComposerやら色々導入して、Laravelで遊ぼうとしたときのこと。
とりあえず、http://<address>/<project_name>/public/
で初期画面見れてほっこり。
このとき、初期画面が見れるのは、routes/web.php
に
こんな感じでルーティングが設定されているからですよね。
Route::get('/', function () { return view('welcome'); });
ただ、今回起こったことは、
下みたいに、ルーティングを追加したときに Not Found が表示されました。
fugaだろうがfooだろうが全部 Not Found。
Route::get('/hoge', function () { return 'Hello World'; });
/
でルーティングしたものは表示されてそれ以外はNot foundなもんで、
プロジェクト側の設定ミスか何かなのかな〜と思ってたらApache側でしたね。
httpd.confの中身を覗いてみると、
<Directory "/var/www"> AllowOverride None Require all granted </Directory> ~ ~ <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory>
<Directory "/var/www"></Directory>
と
<Directory "/var/www/html"></Directory>
の中の AllowOverride
がNoneになってますが、
ここが原因だったみたいです。
それぞれ AllowOverride All
に直して、Apacheを再起動してあげましょう。
$ systemctl restart httpd
これでルーティング上手く行きました。