我是PHP的新手。我正在使用packagist.org的联盟/路由在我的应用程序中进行路由,并且在我的根目录中有一个公用文件夹,其中有一个index.php文件用于路由,如下所示。htaccess自定义url路由使用php路由
require_once '../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$router = new League\Route\RouteCollection;
$router->addRoute('GET', '/acme', function (Request $request, Response $response) {
echo "here";
return "working";
});
$dispatcher = $router->getDispatcher();
$response = $dispatcher->dispatch('GET', '/acme');
$response->send();
.htaccess文件,如果在根文件夹,如下面
RewriteEngine On
RewriteBase /HMT/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule^index.php [QSA,L]
问题是,当我运行显示http://localhost/HMT/acme什么。我试着在public/index.php文件的每一行后面添加一个echo语句,并注意到下面的行是不起作用的。我也认为我的.htaccess可能是问题?
$dispatcher = $router->getDispatcher();
感谢您的帮助,谢谢。
您应该会收到一条错误消息。尝试在索引文件的开头添加以下内容:ini_set('display_errors',1);'用于调试目的。 – nebulousGirl