404 Error When Deploying Laravel On AWS EC2

I am trying to deploy Laravel on Amazon EC2 (Linux AMI). I add .htaccess in the larval directory and laravel/public directory.

<IfModule mod_rewrite.c>
WriteEngine On
RewriteBase /laravel/public/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

When I browser the, the laravel first page works well, but when I browser into a sub page like, a 404 Not Found error appears. How to solve this problem, thanks for your help !



You're doing it wrong. Do no make any changes in a .htaccess file inside a public directory and do not add .htaccess to a Laravel root directory.

You need to point Laravel to a public directory to make it work. For example, if you've installed Laravel in /path_to_laravel/public/ directory, you need to use these settings in your Apache config:

DocumentRoot "/path_to_laravel/public/"
<Directory "/path_to_laravel/public/">

After that restart Apache and your app should work as expected.

Use URLs, like without 'laravel' and 'public'.