You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx环境下WP 4.9.5的Timber/WooCommerce REST API 404故障求助

Troubleshooting WooCommerce REST API 404 Error on WordPress 4.9.5 (Nginx)

Let's walk through the most likely fixes for your 404 error when accessing http://domain.test/wp-json/wc/v2/:

1. Verify Nginx Rewrite Rules

Nginx doesn’t automatically handle WordPress’s pretty permalinks or REST API routes out of the box. Double-check your site’s Nginx config to ensure it includes rules that pass all requests to index.php (which powers the REST API). Here’s the critical section you need:

server {
    # ... other server configs like listen, server_name, root, etc.

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # Explicitly handle wp-json routes to avoid conflicts
    location ~* ^/wp-json/ {
        try_files $uri $uri/ /index.php?$args;
    }

    # Optional: Block direct access to sensitive files
    location ~* /wp-config.php {
        deny all;
    }
}

After updating the config, restart Nginx with sudo systemctl restart nginx (or your server’s equivalent command) to apply changes.

Even if you already enabled permalinks, re-saving the settings can flush WordPress’s internal rewrite rules and fix route mismatches:

  • Go to WordPress Dashboard → Settings → Permalinks
  • Select any option except "Plain" (e.g., "Post name")
  • Click Save Changes (you don’t need to modify anything else—just saving triggers the flush)

3. Check WooCommerce REST API Configuration

WooCommerce’s REST API might have settings that block anonymous access, even for GET requests:

  • Go to WooCommerce → Settings → Advanced → REST API
  • Ensure the "Enable REST API" checkbox is checked (it should be enabled by default, but it’s worth confirming)
  • Note: Some WooCommerce endpoints require authentication for read access, but the base wp-json/wc/v2/ endpoint should return a list of available routes without auth. If this still fails, move to the next step.

4. Test for Plugin Conflicts

Your installed plugins (Timber, ACF PRO, Gravity Forms, etc.) could be interfering with REST API routes. Let’s isolate the issue:

  • Temporarily disable all plugins except WooCommerce
  • Test the http://domain.test/wp-json/wc/v2/ endpoint again
  • If it works, re-enable plugins one by one, testing the API after each. The plugin that causes the 404 to return is the culprit—you can then check for updates or compatibility fixes for that plugin.

5. Verify Core Version Compatibility

While WordPress 4.9.5 and WooCommerce 3.3.5 are technically compatible, outdated versions can have known bugs. If the above steps fail, consider:

  • Updating WordPress to the latest compatible version for WooCommerce 3.3.5
  • Updating WooCommerce to a newer version that supports your WordPress install (if possible)

6. Test the Base REST API Endpoint

First, check if the core WordPress REST API works by visiting http://domain.test/wp-json/. If this also returns a 404, the issue is with WordPress’s REST API itself (not WooCommerce-specific), which points back to Nginx rewrite rules or permalink settings.

内容的提问来源于stack exchange,提问作者stefan0s

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:32:47