.htaccess 拒绝 $_GET 参数
.htaccess denying $_GET params
基本上,我想像这样传递 $_GET 参数:
<a class="btn btn-danger" href="/deleteController.php?delete=<?= $tasks['listid'] ?>"> Delete </a>
但是,我的 .htaccess 文件似乎没有将其视为有效文件:
Warning: require_once(/opt/lampp/htdocs/src/controller/deleteController.php?delete=1): failed to open stream: No such file or directory in /opt/lampp/htdocs/public/index.php on line 14
Fatal error: require_once(): Failed opening required '/opt/lampp/htdocs/src/controller/deleteController.php?delete=1' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/public/index.php on line 14
最后是我的 .htaccess 文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>
如果有人能帮我弄清楚如何让我的 .htaccess 允许 $_GET 参数,并且仍然需要想要的文件,我将不胜感激。
编辑:
index.php 控制器(修复前):
$uri = urldecode($_SERVER['REQUEST_URI']);
if ($uri === '' || $uri === '/' || $uri === '/index.php') {
$uri = '/task_list_Controller.php';
}
require_once(CONTROLLER_PATH . $uri);
您的问题与 Apache 无关。
Warning:
require_once(/opt/lampp/htdocs/src/controller/deleteController.php?delete=1):
failed to open stream:
No such file or directory in /opt/lampp/htdocs/public/index.php on line 14
Fatal error:
require_once(): Failed opening required '/opt/lampp/htdocs/src/controller/deleteController.php?delete=1'
您正在尝试 require_once(.../deleteController.php?delete=1)
当然不会存在,因为文件 deleteController.php?delete=1
不存在。
只有 deleteController.php
。
在第 14 行的文件 /opt/lampp/htdocs/public/index.php
中,我看到您需要 CONTROLLER_PATH.$uri
的文件。
所以问题出在第 9 行,您在其中传递带有查询字符串的 uri。
就这么写吧:
$uri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if ($uri === '' || $uri === '/' || $uri === '/index.php') {
$uri = '/task_list_Controller.php';
}
if (is_file(CONTROLLER_PATH . $uri)) {
require_once(CONTROLLER_PATH . $uri);
}
基本上,我想像这样传递 $_GET 参数:
<a class="btn btn-danger" href="/deleteController.php?delete=<?= $tasks['listid'] ?>"> Delete </a>
但是,我的 .htaccess 文件似乎没有将其视为有效文件:
Warning: require_once(/opt/lampp/htdocs/src/controller/deleteController.php?delete=1): failed to open stream: No such file or directory in /opt/lampp/htdocs/public/index.php on line 14
Fatal error: require_once(): Failed opening required '/opt/lampp/htdocs/src/controller/deleteController.php?delete=1' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/public/index.php on line 14
最后是我的 .htaccess 文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>
如果有人能帮我弄清楚如何让我的 .htaccess 允许 $_GET 参数,并且仍然需要想要的文件,我将不胜感激。
编辑:
index.php 控制器(修复前):
$uri = urldecode($_SERVER['REQUEST_URI']);
if ($uri === '' || $uri === '/' || $uri === '/index.php') {
$uri = '/task_list_Controller.php';
}
require_once(CONTROLLER_PATH . $uri);
您的问题与 Apache 无关。
Warning:
require_once(/opt/lampp/htdocs/src/controller/deleteController.php?delete=1):
failed to open stream:
No such file or directory in /opt/lampp/htdocs/public/index.php on line 14
Fatal error:
require_once(): Failed opening required '/opt/lampp/htdocs/src/controller/deleteController.php?delete=1'
您正在尝试 require_once(.../deleteController.php?delete=1)
当然不会存在,因为文件 deleteController.php?delete=1
不存在。
只有 deleteController.php
。
在第 14 行的文件 /opt/lampp/htdocs/public/index.php
中,我看到您需要 CONTROLLER_PATH.$uri
的文件。
所以问题出在第 9 行,您在其中传递带有查询字符串的 uri。
就这么写吧:
$uri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if ($uri === '' || $uri === '/' || $uri === '/index.php') {
$uri = '/task_list_Controller.php';
}
if (is_file(CONTROLLER_PATH . $uri)) {
require_once(CONTROLLER_PATH . $uri);
}