php - .htaccess denying $_GET params
Get the solution ↓↓↓Basically, I'd like to pass a $_GET param like that:
<a class="btn btn-danger" href="/deleteController.php?delete=<?= $tasks['listid'] ?>"> Delete </a>
However, it seems that my .htaccess file does not see it as a valid file:
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
And finally my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>
If someone could help me figuring out how can I get my .htaccess to allow $_GET params, and still requiring the wanted file, I'd greatly appreciate it.
EDIT:
index.php controller (before the fix):
$uri = urldecode($_SERVER['REQUEST_URI']);
if ($uri === '' || $uri === '/' || $uri === '/index.php') {
$uri = '/task_list_Controller.php';
}
require_once(CONTROLLER_PATH . $uri);
Answer
Solution:
Your problem not related to 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'
You're trying torequire_once(.../deleteController.php?delete=1)
which of course will not exist, since the filedeleteController.php?delete=1
does not exist.
there is onlydeleteController.php
.
In file/opt/lampp/htdocs/public/index.php
on line 14 I saw that You're requiring file byCONTROLLER_PATH.$uri
.
So the problem comes from line 9 where You're passing uri with query string.
simply write it like this:
$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);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.