Back to Community

Understanding and Using WordPress REST API Endpoint URLs

36 threads Sep 17, 2025 CoreRequests and feedback

Content

When working with the WordPress REST API, one common point of confusion is the format of the endpoint URL. Specifically, developers often wonder if the URL structure changes based on their site's permalink settings and which format is the most reliable to use. This guide explains the two primary URL formats and the best practices for accessing the API.

The Two REST API URL Formats

WordPress provides two main ways to construct a REST API endpoint URL:

  • Pretty Permalinks (Post name): When your site uses a "pretty" permalink structure (e.g., /%postname%/), the API base URL is typically:
    https://yoursite.com/wp-json/
  • Plain Permalinks: If your site is using the default "plain" permalink setting, the API base URL uses a query parameter:
    https://yoursite.com/?rest_route=/

The Universal Solution

Analysis of community support threads confirms a key piece of information: the /?rest_route=/ format is always accessible, regardless of which permalink formatting is set on the site. This makes it a universally reliable method for constructing API requests.

Best Practices for Developers

While you can hardcode the ?rest_route= format, the recommended method for developers writing code within a WordPress environment is to use the built-in rest_url() function. This function automatically generates the correct base URL for the REST API based on the site's current configuration, making your code more robust and future-proof.

Hosting and Firewall Considerations

Access to the REST API is generally available on all standard hostings. It is extremely rare for a firewall to block it, but it is not impossible. If you are unable to access the API using either URL method, you may need to check your hosting provider's security rules or mod_security settings.

Summary

To ensure consistent access to the WordPress REST API:

  • For manual testing or direct linking, the https://yoursite.com/?rest_route=/<endpoint> format is a safe bet that works in all environments.
  • For development within plugins or themes, always use the rest_url() function to generate endpoint URLs programmatically.

Related Support Threads Support