Laravel の apache 設定

チュートリアルを進めていて、/tasks の URL に遷移しても、

index.php ではなく、/public/tasks にアクセスしようとしてしまう場合。

 

公式ドキュメント

https://readouble.com/laravel/5.1/ja/installation.html

にも書いてあるが、.htaccess が動作していない可能性がある。

そのときには、apache の .conf ファイルに下記のように設定をする。

<VirtualHost *:80>
    DocumentRoot /path/to/public/
    ServerName foo.example.com
    <Directory /path/to/public>
        Options Indexes
        AllowOverride None
        Require all granted

        Options +FollowSymLinks
        RewriteEngine On

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