Development Shack Technology Understood

WordPress and WP-API RewriteRule, RewriteCond  

WordPress Rules

Here was the simple solution I came up with:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^/(.+) /index.php [QSA,L]

[QSA,L] does 2 things:

  1. It marks the LAST (L) rule to use (so if a URL matches this rule, the engine stops and uses it without consideration of the rules after it)
  2. QSA copies the query string to the destination

I found out the hard way that [QSA, L] was throwing an error, but [QSA,L] wasn't.

If you didn't see the difference, read that again (see that space?)!

WP-API URL Rules

RewriteRule ^/api(/.+) /index.php?json_route=$1 [QSA,L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^/(.+) /index.php [QSA,L]

Notice, how I placed the /api/ rule BEFORE the normal WordPress rule!

Now, you should be able to access the WP-API's:

http://localhost/api/posts