Slim框架-PHP没有正确路由-有什么想法吗?

Slim框架-PHP没有正确路由-有什么想法吗?,php,xampp,slim,Php,Xampp,Slim,我正在使用XAMPP运行Web服务器-它在'http://localhost/mvc-framework/public/“作为根 但当我尝试使用“联系人”链接导航时,它会转到http://localhost/contact我得到了一个“404”错误 My routes.php当前的外观如下: <?php // Routes $app->get('mvc-framework/public/contact', function ($request, $response, $args)

我正在使用XAMPP运行Web服务器-它在'http://localhost/mvc-framework/public/“作为根

但当我尝试使用“联系人”链接导航时,它会转到http://localhost/contact我得到了一个“404”错误

My routes.php当前的外观如下:

<?php
// Routes

$app->get('mvc-framework/public/contact', function ($request, $response, $args) {
    // Render index view
    return $this->view->render($response, 'contact-form.phtml', $args);
});

$app->get('/[{name}]', function ($request, $response, $args) {
    // Sample log message
    $this->logger->info("Slim-Skeleton '/' route");

    // Render index view
    return $this->view->render($response, 'about.phtml', $args);
});
是否有明显的地方我出错了?

public/directory只是Web服务器的DocumentRoot,因此不应该是url基本路径的一部分

正确的url:http://localhost/mvc-framework/

在DocumentRoot的子目录中运行Slim应用程序时,还必须定义Slim basePath。在您的特定情况下,它是/mvc框架:

$app->setBasePath'/mvc framework'; 应在不使用基本路径的情况下定义路由:


说它在运行http://localhost/mvc-framework/public/“作为根。这有点让人困惑。你能澄清一下吗?另外,你能告诉我们你的项目的目录结构吗,web服务器配置中DocumentRoot的值以及.htaccess文件的内容?Hi@odan-感谢您的帮助-看起来我没有从正确的位置运行Apache服务器-我更改了“httpd.conf”中的“DocumentRoot C:/xampp/htdocs”并重新启动了服务器-现在它工作得很好!感谢您对routes.php的帮助!