简体   繁体   中英

slim framework Page not Found

i don't understand, that's not the first time i launch a project under slim but i have an unexplained error.

My folder:

c:\wamp\www\slim

I created "public" folder

c:\wamp\www\slim\public

Like the doc say, i create 2 .htaccess: In root:

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

In public folder:

# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

And here my index.php in public folder:

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../vendor/autoload.php';

$app = new \Slim\App;
var_dump($_SERVER);

$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello");

return $response;
});

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");

return $response;
});

$app->run();

if i try to go to: http://localhost/slim/ :: Page not found if i try to go to: http://localhost/slim/hello/Alex :: Page not found

It only works if i set my routes like this:

$app->get('/slim/hello/{name}', function (Request $request, Response $response, array $args) {...

I have to add "slim/" in route.

Why? On my other computer it works. The only thing that change is the version of apache: 2.3.4 and 2.3.23 Please help.

check that you add a file to c:\\wamp\\www can you access it on localhost, if you can't there is an issue with your configuration.

check that both versions are the exact code, one isn't using groups to wrap routes as they do in either of these: discourse.slimframework.com/t/add-prefix-to-all-routes/515/4 or slimframework.com/docs/v3/objects/router.html#route-groups

Not using groups and want to support Slim from a subdirectory: Follow the steps described in this issue comment to github.com/slimphp/Slim/issues/1529#issuecomment-341734546 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM