I am trying to write a simple RESTful php application. I am trying to write a single index.php router.
My .htaccess file has
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule api/^(.*)$ api/index.php?_url=/$1 [QSA,L]
</IfModule>
I added RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$to make the trailing slash see here .
Calling var_dump($_POST);or var_dump($_GET);still returning an empty array, POST values are still discarded. Send GET and POST GET returns under evaluation $_SERVER['REQUEST_METHOD'];.
How to implement this correctly? In addition, I cannot use the library and must implement my own router.
Any help or advice appreciated.
EDIT:
It started from scratch:
URL for requests must be http://localhost/api/*
The current .htaccess file located in the api folder is as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ controller.php?do=$1 [L,QSA]
where controller.phpis in/var/www/api
Vhost file /etc/apache2/sites-available
called api.conf
:
<VirtualHost *:*>
ServerName test.example.com
ServerAlias www.test.example.com
DocumentRoot /var/www/api/
<Directory "/var/www/api/">
Allow from all
AllowOverride all
Options +Indexes
</Directory>
</VirtualHost>
- :
The requested URL /api/something was not found on this server.