#39432 closed defect (bug) (fixed)
index.php/wp-json/ does not work
Reported by: | ccprog | Owned by: | rmccue |
---|---|---|---|
Milestone: | 4.7.3 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch fixed-major |
Focuses: | Cc: |
Description
While you need mod_rewrite for discovery via http://example.com/wp-json/ to work, I run into problems without it. The Link resonse header then says
<http://example.com/index.php/wp-json/>; rel="https://api.w.org/"
but calling this results in
{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}
The same error is returned on my public site https://browser-unplugged.net/index.php/wp-json/ where rewrite is working. The response is obviously given by the REST API. The REST API plugin was never installed, and I did flush the rewrite rules as proposed in 39424
For sites like developer.wordpress.org or demo.wp-api.org, the address works.
http://example.com/index.php/index.php/?rest_route=/, http://example.com/index.php/wp-json/wp/v2/ and all endpoints work as expected.
Attachments (1)
Change History (14)
#2
@
8 years ago
- Keywords reporter-feedback added
@ccprog Can you provide details on your server and mod_rewrite configuration?
FYI: Discovery does work even if mod_rewrite is not enabled via https://browser-unplugged.net/index.php?rest_route=/
#3
@
8 years ago
The public website has PHP 5.6.27, Apache/2.2.31 (Unix) with this .htaccess:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
cgi-fcgi settings:
cgi.check_shebang_line 1 1 cgi.discard_path 0 0 cgi.fix_pathinfo 1 1 cgi.force_redirect 0 0 cgi.ignore_repeated_errors 1 1 cgi.nph 0 0 cgi.redirect_status_env no value no value cgi.rfc2616_headers 0 0 fastcgi.logging 1 1
Permalinks settings are "Month and name", Link header points to /wp-json/
.
My development system is a PHP 5.6.29-0+deb8u1, lighttpd/1.4.35, no equivalent to .htaccess.
cgi-fcgi settings:
cgi.check_shebang_line 1 1 cgi.discard_path 0 0 cgi.fix_pathinfo 1 1 cgi.force_redirect 1 1 cgi.nph 0 0 cgi.redirect_status_env no value no value cgi.rfc2616_headers 0 0 fastcgi.logging 1 1
Permalinks settings are "Post name", Link header points to /index.php/wp-json/
.
I am aware that ?rest_route=/
works, but that is not what the Link header and rest_url('')
deliver, and therefore autodiscovery fails. For example in the REST API Console plugin, the reference panel remains empty.
The essence is, as I understand it now, there are setups where
$_SERVER[REQUEST_URI] = '/index.php/wp-json/' $_SERVER[PATH_INFO] = '/wp-json/'
The uri is then run through wp_rewrite, but PATH_INFO is not.
#5
@
8 years ago
- Milestone changed from Awaiting Review to 4.7.2
- Owner set to rmccue
- Status changed from new to accepted
This appears to be a bug. /wp-json/
should be stripped from PATH_INFO
when we use that. However, it's strange that it's using that rather than the rest_route
query var which is already available.
This requires further investigation.
#6
@
8 years ago
- Keywords has-patch added
The issue was that the $path
being passed in was empty due to untrailingslashit
, but PATH_INFO
was not empty. We can fix this by ensuring $path
is never empty: the only case this can happen is when the index is being requested.
39432.diff ensures $path
is never empty. Note the empty
check at the start of rest_api_loaded()
already determines that $path
can't actually be empty.
#8
@
8 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for backporting to 4.7.2.
We should also consider removing the PATH_INFO fallback, which really only existed for a very old legacy use case (a separate wp-json.php
file). Technically, that may break backwards compatibility, but I highly doubt anyone is actually able to use it right now, so I don't think it would break any real code.
The error can be traced to WP_Rest_Server::serve_request:
if ( empty( $path ) ) { if ( isset( $_SERVER['PATH_INFO'] ) ) { $path = $_SERVER['PATH_INFO']; } else { $path = '/'; } }
$_SERVER['PATH_INFO']
contains/wp-json/
on my setup.While this is plausible if mod_rewrite is not active, the success on developer.wordpress.org raises the question if a webserver rewrite may or may not change the content of PATH_INFO?