Woocommerce 4 REST API 404错误求助:所有接口返回404但其他站点可正常调用
Hey there, let's break down how to troubleshoot this 404 issue with your WooCommerce API endpoints—since you mentioned another site works fine with the same setup, we can narrow things down step by step:
1. Double-Check Permalink Settings
WooCommerce REST API relies on WordPress's "pretty permalinks" to work correctly. Head to your WordPress dashboard > Settings > Permalinks and make sure you're not using the "Plain" structure (like ?p=123). Pick any other option (e.g., "Post name") and hit "Save Changes"—even if it looks correct, this flushes the rewrite rules which often fixes 404s for API endpoints.
2. Validate API Key & Endpoint Configuration
- Go to WooCommerce > Settings > Advanced > REST API and confirm:
- The API key you're using is active, has the right permissions (read/write as needed), and is tied to a valid user account.
- The base endpoint URL matches what you're using in requests. It should follow this pattern:
https://yourdomain.com/wp-json/wc/v3/(double-check the API version matches your working site—e.g.,v2vsv3can cause mismatches).
3. Rule Out Plugin/Theme Conflicts
- Temporarily deactivate all plugins except WooCommerce, then test the API again. If it starts working, reactivate plugins one by one to find the conflicting one.
- Switch to a default WordPress theme (like Twenty Twenty-Four) for a minute—custom themes sometimes modify rewrite rules or block API access unintentionally.
4. Check Server & .htaccess Settings
- For Apache servers: Open your root
.htaccessfile and ensure it includes the standard WordPress rewrite rules. If it's missing or modified, replace it with:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress - For Nginx servers: Confirm your server block has rules to pass API requests to
index.php(your hosting provider can help with this if you're unsure). - Reach out to your host to make sure
mod_rewrite(for Apache) is enabled, and there are no server-level firewalls or restrictions blocking/wp-json/endpoints.
5. Cross-Compare with Your Working Site
Since your other site works, line up these details to spot discrepancies:
- WooCommerce version (major version mismatches can break API compatibility)
- WordPress version
- PHP version (WooCommerce has minimum PHP requirements—older versions can cause unexpected errors)
- Request headers (confirm you're sending the same
Authorizationheader, content type, and request method as the working site)
6. Test with Direct API Requests
Use a tool like Postman or curl to send a simple, direct request to rule out issues with your client code. For example:
curl -X GET https://yourdomain.com/wp-json/wc/v3/products -u your_consumer_key:your_consumer_secret
If this still returns 404, the problem is almost certainly with the site/server configuration, not your code.
内容的提问来源于stack exchange,提问作者John Doe

