Hello, I happen to be creating a PHP REST API and I do not want to use a framework but I have the following problem
I want to create a request by the GET method in which I send the ID of a product to look for it in the database.
That is:
http://localhost/ws_php/productos/1
The problem is that I implemented a .htaccess so that all the requests reach the index.php with the following code that I found on the web
RewriteEngine On
#RewriteRule ^([^/]*)/([^/]*)$ index.php?url=$1&username=$2 [L]
RewriteRule ^([^/]+)/? index.php?url=$1 [L,QSA]
when I print the variable $_GET['url'];
to find the ID that I sent, it only shows up to "products" without the ID
PHP code
<?php
require_once('db.php');
if ($_SERVER['REQUEST_METHOD']=="GET"){
$var = $_GET['url'];
print_r($var);
}else if($_SERVER['REQUEST_METHOD']=="POST"){
echo" POST METHOD ";
}else{
http_response_code(405);
}
?>
All requests go to the index except those that point to the image folder
localhost/ws_php/img/miimagen.jpg