Home > Software engineering >  404 on GET request Laravel 9
404 on GET request Laravel 9

Time:03-16

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:

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 [email protected]
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

CodePudding user response:

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 [email protected]
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

  • Related