Rewritten URL causes 406 error

379 views Asked by At

I'm trying to create a RESTful API and document. However I seem to be getting a weird error I can't figure out how to fix.

This works:

curl --header "Accept: application/json" http://api.example.com/v1/method.php?key=test

However if you remove the ".php" extension and run this:

curl --header "Accept: application/json" http://api.example.com/v1/method?key=test

You should get a 406 error if you run it. Now if you drop the header that the curl is sending, both of the requests work just fine. However the documentation tool(swagger) I'm using requires it.

Here is my rewrite rule (found here):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
1

There are 1 answers

2
DJ MHA On

Try

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule method method.php [L]

Your operation did not fail.

Your backend service is saying that the response type it is returning is not provided in the Accept-Type HTTP header in your Client request.

Ref: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

  • Find out the response (content type) returned by Service.
  • Provide this (content type) in your request Accept header.

http://en.wikipedia.org/wiki/HTTP_status_code -> 406