Problem with Routes - Page Not Found


#1

Hi,
I’m trying to create a web service here using Slim3 with PHP and mySQL. When I try to connect to this web service (http://webservice.test/v1/test ), the browser and my postman return “Page not Found”
I’m t

Here is my index.php

$app->get('/teste', function (Response $response) use ($app) {
$response->getBody()->write("Test here");
return $response; });

$app->post('/createuser' , function () use ($app)  {
verifyRequiredParams(array('first_name', 'last_name', 'username', 'password'));
$response = array();
$first_name = $app->request->post('first_name');
$last_name = $app->request->post('last_name');
$username = $app->request->post('username');
$password = $app->request->post('password');
$db = new DbOperation();
$res = $db->createUser($first_name, $last_name, $username, $password);
if($res == 0) {
    $response["error"] = false;
    $response["message"] = "User created";
    echoResponse(201, $response);
} else if($res == 1) {
    $response["error"] = true;
    $response["message"] = "Oops, error while creating a user";
    echoResponse(200, $response);
} else if($res == 2) {
    $response["error"] = true;
    $response["message"] = "E-mail already exist";
    echoResponse(200, $response);
} });

And here is my .htaccess

RewriteEngine On 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d 
RewriteRule ^ index.php [QSA,L]

I’m trying to create a web service here using Slim3 with PHP and mySQL. When I try to connect to this web service, the browser and my postman return “Page not Found”

Here is my index.php

$app->get(’/teste’, function (Response $response) use ($app) {
$response->getBody()->write(“Fuck off”);
return $response; });

$app->post(’/createuser’ , function () use ($app) {
verifyRequiredParams(array(‘first_name’, ‘last_name’, ‘username’, ‘password’));
$response = array();
$first_name = $app->request->post(‘first_name’);
$last_name = $app->request->post(‘last_name’);
$username = $app->request->post(‘username’);
$password = $app->request->post(‘password’);
$db = new DbOperation();
$res = $db->createUser($first_name, $last_name, $username, $password);
if($res == 0) {
$response[“error”] = false;
$response[“message”] = “User created”;
echoResponse(201, $response);
} else if($res == 1) {
$response[“error”] = true;
$response[“message”] = “Oops, error while creating a user”;
echoResponse(200, $response);
} else if($res == 2) {
$response[“error”] = true;
$response[“message”] = “E-mail already exist”;
echoResponse(200, $response);
} });
Here is my .htaccess

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

I know the problem is not the apache because I created a php file inside the directory and works fine.

Can anyone helps me?

Thanks


#2

Your route is /teste but you are testing against: /v1/test.

Try to change the route to this:

$app->get('/v1/test', ...

#3

Thanks for your reply odan .
I made the change and still the same problem.