I'm encountering a NotFoundHttpException error in Laravel 9 despite having what seems to be the correct .htaccess configuration and virtual host setup. Here are the details of my setup:
.htaccess inside the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Header set X-Frame-Options SAMEORIGIN
</IfModule>
Virtual Host Configuration:
<VirtualHost *:80>
ServerAlias *.afterhire.local
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html/afterhire/public/"
<Directory "/var/www/html/afterhire/public/">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Despite these configurations, when I try to access my any Laravel routes or its base url like 127.0.0.1:8000 or admin.afterhire.local, I encounter a NotFoundHttpException. What could be the possible reasons for this error, and how can I troubleshoot and resolve it?
Rather than running your site trough a http server such as Apache, can you run it using php artisan serve
.
If you get the same error then the issue will be in your routes/web.php
or something further in the Kernal, Middleware etc.
Otherwise it'll be in your php config. Check you have the required php modules enabled, including URL Rewrite.
If all these checks pass, the best suggestion I have is to start from a clean Laravel project, and copy over your code in chucks to see where you get the error.