I am creating a mobile application(flutter) that works with api on Laravel. The api should work but there are problems. I'm trying to figure it out, although I don't have previous experience with Laravel (I have experience with PHP). so on server Cpanel. when i try to call the api i get an error
404 Not Found
body:
The requested URL was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request
This is a fairly common problem, the points I checked are the following points.
the api is in the public_html folder, some folders inside:
app
routes
bootstrap
checked file public_html/.htaccess
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
I changed it to:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
executed the following commands
php artisan route:clear
php artisan route:cache
after that i execute the command
php artisan route:list
result:
I try the following options for the url:
https://appdomain.com/api/v1/login
https://appdomain.com/api/v1/Check-login
https://appdomain.com/api/v1/user-login
https://appdomain.com/api/login
https://appdomain.com/api/Check-login
https://appdomain.com/api/user-login
https://appdomain.com/login
https://appdomain.com/Check-login
https://appdomain.com/user-login
but each of these urls return a 404 error.
Laravel - version 5.5.50
part of api.php
Route::group(['prefix' => 'v1'], function () {
Route::post('/user-login',['as' => 'login','uses' =>
'api\v1\UserController@user_login']);
});
7. when I added file public_htm/index.php - any request to api returns that file
Which url is correct?
What else can I check?
How can this be fixed?
Any advice - I will be very grateful.
Method 1:
Change Document Root to public_html/public
and upload the source code to public_html
.
Method 2:
Upload the source code except public
folder to the parent folder of public_html
folder. And upload the files in public
folder to public_html
folder.
Add the following code to public_html/index.php
:
$app->bind('path.public', function() {
return __DIR__;
});