.htaccess and proxy settings for routing a decoupled REST API consuming theme

Developing a decoupled front-end consuming the REST API...

I'm using create-react-app so can enter a proxy field corresponding to WP in my package.json and write my calls like fetch('/wp-json/v2/pages/...') if I run yarn start from the front-end directory...

I'd love to actually have this theme in my wp-content/themes/my-theme directory though

I'm no .htaccess god

How can I make so that:

  • Generic requests like mysite.com/jibble/jabble are handled by my SPA routing
  • Protected routes like mysite.com/wp-admin/* and mysite.com/wp-content/uploads/* are still handled by Apache

Topic plugin-json-api rest-api htaccess api theme-development Wordpress

Category Web


Ok this probably has a superfluous few lines but this works for me:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^static/(.*)$ /wp-content/themes/MYTHEME/static/$1 [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.