我是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