404 Not Found - on Laravel 5.8 when the route already exists

Viewed 79

I have a laravel 5.8 project on a hosted site and I recently added JWT Authentication in order to create APIs for mobile applications. Every API I have created is working fine and sending a proper response, except sometimes I am getting a 404 Not Found error even when the route exists in api.php which I'm calling as https://app.mydomain.com/api/apiname.

Here's how my .htaccess file looks as below.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

and my api.php in Routes is as below,

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\ApiAuthController;
use App\Http\Controllers\ApiSettingsController;
use App\Http\Controllers\ApiManageUsersController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

//api test
Route::get('/my-api-endpoint',  function  (Request $request)  {

  return response()->json(['Hello Laravel 7']);

});

//Auth Routes
Route::post('login', 'ApiAuthController@login');
Route::post('logout', 'ApiAuthController@logout');
Route::post('refresh', 'ApiAuthController@refresh');
Route::post('/rest/re_login', 'ApiAuthController@re_login');
Route::GET('/language_json', 'ApiAuthController@language_json');

//Settings Routes
Route::GET('/branding_info', 'ApiSettingsController@branding_info');
Route::POST('/update_branding_info', 'ApiSettingsController@update_branding_info');
Route::GET('/grading_master', 'ApiSettingsController@grading_master');
Route::POST('/grad_cat_active_inactive', 'ApiSettingsController@grad_cat_active_inactive');
Route::GET('/grading_master/view_lessons', 'ApiSettingsController@view_lessons');
Route::POST('/lesson_active_inactive', 'ApiSettingsController@lesson_active_inactive');
Route::GET('/driving_conditions', 'ApiSettingsController@grading_master');


//Manage Users Routes
Route::GET('/Manage_users/{user_type}', 'ApiManageUsersController@Manage_users');

Note: I am using Plesk to access my server. Please help me out with this situation.

and here's a screenshot of 404 error which I get in postman, enter image description here

Thanks in advance....

0 Answers
Related