4

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.
Community
  • 1
  • 1
andrsnn
  • 1,591
  • 5
  • 25
  • 43

1 Answers1

0

I solved this problem:

Apache overwrote the default.conf file in the sites-available folder when I performed an update which I overlooked...

I needed to add to 000-default.conf

<Directory /var/www/>
     AllowOverride All

I discovered mod_rewrite was now off:

in_array('mod_rewrite', apache_get_modules());
//or
var_dump(apache_get_modules());

so to reenable:

a2enmod rewrite

service apache2 restart

Hope this helps others.

andrsnn
  • 1,591
  • 5
  • 25
  • 43