I need some help it been two days and I can't find the problem. I am developing Android application for my Final Year Project it all going smooth until it gives me 404 not found error after uploading my API files in Filezilla I tried rewrite base in HTA access but it just not working or I am doing it incorrectly who knows.
public/index.php
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require '../vendor/autoload.php';
require '../includes/DbOperations.php';
$app = AppFactory::create();
$app->setBasePath("/mylife/public");
$app->addErrorMiddleware(true, true, true);
// My routes
// ...
$app->run();
I have two .htacess one inside public folder and outside folder.
Outside folder
outside public folder
Options All -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
# Redirect to the public folder
RewriteEngine On
RewriteBase /mylife/
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
# Redirect to HTTPS
# RewriteEngine On
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Inside public folder
Options All -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to HTTPS
# RewriteEngine On
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Some hosts may require you to use the `RewriteBase` directive.
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the
# absolute physical path to the directory that contains this htaccess file.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
The error it says is
[05-Nov-2023 02:05:24 Asia/Kuala_Lumpur] 404 Not Found
Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 76
Trace: #0 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/Routing/RouteRunner.php(56): Slim\Middleware\RoutingMiddleware->performRouting()
#1 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(76): Slim\Routing\RouteRunner->handle()
#2 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/MiddlewareDispatcher.php(121): Slim\Middleware\ErrorMiddleware->process()
#3 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/MiddlewareDispatcher.php(65): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
#4 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/App.php(199): Slim\MiddlewareDispatcher->handle()
#5 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/vendor/slim/slim/Slim/App.php(183): Slim\App->handle()
#6 /home/sabrisae/public_html/ruangprojek/sadiahcafe/mylife/public/index.php(601): Slim\App->run()
#7 {main}
I know if it accessible different error will come out like the parameters is missing or so.
i tried a lot of ways changing the link or the base url or .htacess or the database it just plain doesn't work on it also the index.html files are fine not capitalise or anything because on my computers it work.
The main issue here is that the Slim basePath is not correctly configured because the
publicdirectory can never be part of Slim's basePath. The basePath is everything under thepublicpath. It is not "valid" to have thepublicdirectory in your URL path. Thepublicdirectory should be configured as the Apache DocumentRoot. If you place your Slim app not directly under the Apache DocumentRoot then you need to define the Slim basePath.I would try to remove or comment out the
RewriteBase /mylife/setting, because this could cause a "conflict" with the Slim basepath.Then configure the correct basePath without the public path, for example
If this is not working, I would recommend installing the Slim BasePathMiddleware. This middleware is able to detect and configure the basePath for Slim.