The correct solution is to add the redirect to index.php
in your theme – this will ensure only frontend, non-api based requests are handled.
Sniffing wp-json
in the request is dodgy at best, and will all out break if another plugin overrides the endpoint (which you can do, it’s pluggable).
<?php
wp_redirect( 'http://example.com/', 301 );
exit;
…in wp-content/themes/your-theme/index.php
. And make sure your theme has no other template files, other than a blank functions.php
, and the theme’s style.css