以下是我在index.php中的代码:
$f3 = require_once(dirname(dirname(__FILE__)). '/lib/base.php');
$f3 = \Base::instance();
echo 'received uri: '.$_SERVER['REQUEST_URI'].'<br>';
$f3->route('GET /brew/@count',
function($f3,$params) {
echo $params['count'].' bottles of beer on the wall.';
}
);
$f3->run();
这是英语文本,翻译成中文如下:
这是我访问的URL:http://xx.xx.xx.xx:8090/brew/12
但我得到了一个404错误:
received uri: /brew/12
Not Found
HTTP 404 (GET /12)
“奇怪的事情是,F3中的URI现在是“/12”,而不是“/brew/12”,我想这就是问题所在。”
“当我检查base.php(3.6.5)时,$ this->hive ['BASE'] =“ / brew”,$ this->hive ['PATH'] =“ / 12”。 但是,如果F3只使用$ this->hive ['PATH']来匹配预定义路由,则它将无法匹配它们。”
“如果我更改路由为:”
$f3->route('GET /brew',
如果使用URL:http://xx.xx.xx.xx:8090/brew,那么该路由将无问题地匹配。在这种情况下,$this->hive ['BASE'] = ""和$this->hive ['PATH'] = "/brew"。如果F3将$this->hive ['PATH']与预定义路由进行比较,则它们将彼此匹配。
另外,我正在使用PHP内置的Web服务器,因为$_SERVER['REQUEST_URI'](base.php使用)返回正确的URI,所以我认为我的.htrouter.php中的URL重写没有任何问题。
有什么想法吗?我错过了什么?
请在此添加.htrouter.php的内容。
<?php
#get the relative URL
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
#if request to a real file (such as a html, image, js, css) then leave it as it is
if ($uri !== '/' && file_exists(__DIR__ . $uri)) {
return false;
}
#if request virtual URL then pass it to the bootstrap file - index.php
$_GET['_url'] = $_SERVER['REQUEST_URI'];
require_once __DIR__ . './public/index.php';
$_SERVER['SCRIPT_NAME']
,在我的情况下是/index.php
。注意:我正在使用框架 edge version,没有任何.htrouter.php
。你的.htrouter.php
的内容是什么?你尝试跳过它了吗? - xfra35public/
,因此你应该使用-t public/
来替换-t ./
。同时删掉.htrouter.php
,它没有任何帮助。所以最终命令是:php -S 0.0.0.0:8090 -t public/
。 - xfra35