I would like to hide /wp-json/
from url since I don't want anyone to know that website is built on wordpress. I tried rewriting rules in .htaccess
, but /api
only redirects to /wp-json
so this is not what I trully want.
RewriteRule ^api/(.*)$ /wp-json/$1 [R,L]
These are not working at all:
RewriteRule ^api$ /wp-json [L]
RewriteRule ^api/(.*)$ /wp-json/$1 [L]
I also tried site_url hook event, but unfortunately it is not working at all:
add_filter('site_url', 'api_filter', 10, 3);
function api_filter($url, $path, $orig_scheme) {
$old = array('/(wp-json)/');
$new = array('api');
return preg_replace($old, $new, $url, 1);
}
The WordPress REST API provides endpoints for WordPress data types. This allows developers to interact with sites remotely by sending and receiving JSON objects. However, most website owners do not need these features, and it may be smarter to disable the WordPress JSON REST API.
More precisely, it allows you to specify which routes can be accessed by unauthenticated users or users with specific user roles. To set this, navigate to Settings > Disable REST API. Then choose the appropriate user type with the Rules for: option and set the rules you want in the Manage Rules section below.
Restrict Access to WordPress REST API To disable the WordPress REST API for the anonymous users, you can require authentication for all REST API requests by adding an is_user_logged_in check to the rest_authentication_errors filter in a child theme's functions. php file.
You can use the filter rest_url_prefix
to do the rewrite:
add_filter( 'rest_url_prefix', function() {
return 'api';
});
Remember to visit Settings->Permalinks to flush the permalinks after adding the above code to functions.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With