Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

404 on GET request Laravel 9

I’m working on a project with the new version of laravel. My other projects are all previous versions. I tried every artisan clean method, to make everything clear. I checked the server reqs, those are exact the same how I run my other laravel 8 projects.

But when I request by Postman my api, it returns a 404 page instead of the actual action.

route:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

GET|HEAD   api/token ... generated::*** › UserController@tokenRequest

api.php:

Route::get('token', [UserController::class, 'tokenRequest']);

I just return a simple response with a token. If there is a php error I’ll see it and will not return with a 404, so this is weird. I had the same problem with my other projects but or it was just a mod_rewrite issue, but I all checked those options. Every is set correctly in the .conf. I use apache on my Ubuntu 20.04 server, like my other projects. The only difference is the Laravel version.

Url that I use:

https://example.com/directory/api/token

My public directory url is working perfectly.

https://example.com/directory/public

My custom domain .conf

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@domain1.com
DocumentRoot /var/www/html

<Directory /var/www/html>
    Options -Indexes +FollowSymLinks
    AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined

>Solution :

I usually setup vhost for each project and this is how it looks like for me:

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@domain1.com
DocumentRoot /var/www/html/example.com/public

<Directory "/var/www/html/example.com/public">
    AllowOverride All
    ReWriteEngine On
    Options Indexes MultiViews FollowSymLinks
    Order allow,deny
    allow from all
    Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined

and this worked for all my laravel apps

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading