I am attempting to write a simple RESTful php application. I am attempting to write a single index.php router.
The .htaccess file I currently have is
<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 force a trailing slash as seen here.
Calling var_dump($_POST);
or var_dump($_GET);
still returns an empty array, POST values are still being dropped. Sending a GET and a POST both returns a GET when evaluating: $_SERVER['REQUEST_METHOD'];
.
How do I implement this correctly? Also, I cannot use a library and must implement my own router.
Any assistance or advice appreciated.
EDIT:
Started over from scratch:
Url for requests should be http://localhost/api/*
Current .htaccess file located in the api folder looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ controller.php?do=$1 [L,QSA]
where controller.php
is sitting in /var/www/api
Vhost file in /etc/apache2/sites-available
is titled api.conf
and looks like this:
<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>
Still having the same problem:
The requested URL /api/something was not found on this server.