Reputation: 214
I'm trying to create a RESTful API on a VirtualHost on my Apache 2.4 server (on Ubuntu). I have a php file named dbManager.php
which I am using a RewriteRule to look like an api
directory. It's working great except for PUT and DELETE commands, which are returning 403 errors. Here's a redacted version of my conf file:
<VirtualHost *>
ServerAdmin [email protected]
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<Limit PUT DELETE>
Require all granted
</Limit>
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Well, the PUT and DELETE still aren't working and returning 403. I'm also worried that I don't really want to allow PUT and DELETE everywhere on the directory, but only through the dummy api
directory. What's the right way to do this?
Upvotes: 2
Views: 4713
Reputation: 214
I have managed to solve my question, but I don't really understand why it works:
<VirtualHost *>
ServerAdmin [email protected]
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /path/to/local/dir/>
Require all granted
Satisfy All
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Best I can figure out, getting a 403 means that it's access being blocked, and not the type of HTTP request (which would result in a 405, not a 403). And the access problem is on the local directory, so it needs a special section for it. But I really don't understand why the two lines I put there make things work. The Require
directive, that sort of makes sense. But the Satisfy
directive, from what I can tell from the documentation, should default to All
.
And yet when I remove either line, it doesn't work.
Upvotes: 1