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

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,
Thanks in advance....

Related

Page refresh returns 404 error on deployed vuejs vue-router apllication

The homepage/base url of the app can be refreshed with no issues. but other pages return 404 on page refresh. Please are there any work around for this?
Here is a screenshot of the 404.
[1]: https://i.stack.imgur.com/lc8xD.png
It happens because Vue routing is only on the frontend side. So when you refresh the page it goes backend server. And it checks for any files to satisfy the request.
To solve this issue. You have to tell your apache webserver to handle it for your front end Vue app.
Try adding this to your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
The solution that worked for me:
In /etc/apache2/sites-available/"yourAppDomain".conf add to the end:
FallbackResource /index.html
</VirtualHost>
Page refresh returns 404 error VueJs (mode:history) with Laravel:
The solution that worked for Laravel:
Assuming your entry point is the index method, you just need to add this route at the bottom of your routes/web.php file.
Route::get('{any}', function () {
return view('welcome');
})->where('any','.*');

Laravel Project Not Running On Server

I have deployed my laravel project on server. When I hit the url it gives me error but no log is generated in log folder.
This page isn’t working
[Domain Name] is currently unable to handle this request.
HTTP ERROR 500
I have moved the public folder contents to root directory and edited the index.php.
I checked the permission for storage, vendor and bootstrap folder and they have required permission.
index.php
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Server.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
.htaccess
<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]
</IfModule>
The project is hosted on shared hosting and I've used filezilla to upload it on server. What else I need to do to make it work. This is my first uploading the project on the server.

yii2 rest api url rewriting (hide directories)

I would like to use clean urls on my yii2 rest api.
I'm having clean urls for my frontend application but I'm failing to create clean urls for my yii2 rest api application.
I created the rest api by following the tutorial (Yii2: RESTful api: tutorial). The rest api uses a module for versioning.
Two .htaccess files have been created.
One file in my root and an another one in my "api/web" directory.
root .htaccess file
RewriteEngine on
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteCond %{HTTP_HOST} ^api.localhost [NC]
RewriteRule ^(.*)$ api/web/$1 [L,PT]
'api/web' .htaccess file
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule ^(.*)\?*$ index.php?r=$1 [L,QSA]
Browsing to 'http://api.localhost.com/v1/music' gives a 404 page not found error.
While 'http://api.localhost.com/api/web/v1/music' returns results
(I would like to hide 'api/web/' in my url)
'request' => [
'baseUrl' => str_replace('/api/web', '', (new \yii\web\Request())->getBaseUrl()),
],
Add this request component config in your main api config
Configure the host file to look in /project_folder/api/web

Codeigniter 404 page not found

I have been developing a Codeigniter website locally for with a WAMP server on Windows, everything working fine. I uploaded the files to a Ubuntu server to a virtual directory and configuration the URL and .htaccess. The rewrite rule works like it should but now I get 404 when I try to access the site or any other controller link. The logs state that it cannot find the controller, I checked the files to make sure they were uploaded correctly.
At this point and I at a loss, I have a hunch that it is a configuration issue with Apache but I have checked all the configs that I know. What would cause a 404 error?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
You have activated the module rewrite? If not, turn it on and restart wamp.
Also try to put index.php before the controller, may resolve the problem.
In CI 3.0, All Class names must have the first letter capitalized with the rest of the name lowercase.
Example: Where Model_name is the name of your class, this is how the class should be;
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
}
Then, the model should be loaded like this in the controller;
$this->load->model('user_model');
Please refer to this link: http://www.codeigniter.com/userguide3/general/models.html

Htaccess mod rewrite don't work

I have a project with two applications: a frontend (in AngularJs) and a backend (in Phalcon). I my server document root i have two folders and one htaccess:
public_html
- api
- controllers
- index.php
- app
- .htaccess
The .htaccess have the next configuration:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/(.*)$ api/index.php?_url=/$1 [QSA,L]
</IfModule>
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
So, when i send a POST request (for example) to http://mydomain/api/sessions, the result is 404 not found. The router configuration is:
$router->addPost('/sessions', array(
'controller' => 'sessions',
'action' => 'post'
));
In my localhost works fine with this configuration. But, in my VPS not.
Any ideas ?
Update 1:
If i don't use any REST service, accessing via http://mydomain/api the Phalcon index controller is loaded.
Update 2:
If i try to access a REST service using a Phalcon url like http://mydomain/api/index.php?_url=/licenses works fine.
i found the problem. the virtual host configuration file had not the next lines:
<Directory "/var/www/domain/public_html">
Options All
AllowOverride All
Allow from all
</Directory>
You can sometimes get away with relative path substitutions in the document root, however, you should make the RewriteRule substitution root-relative (starts with a slash), or specify a RewriteBase / directive after you enable the rewrite engine in order to explicitly specify the URL prefix.
RewriteRule ^api/(.*)$ api/index.php?_url=/$1 [QSA,L]
Becomes:
RewriteRule ^api/(.*)$ /api/index.php?_url=/$1 [QSA,L]