Hi! 👋 The issue you’re experiencing with the REST API and the 404 errors for posts on your WordPress multisite installation may indeed be related. Here are ideas to help you troubleshoot and resolve this problem:
- Check Permalinks Settings: Go to your WordPress dashboard, navigate to “Settings” > “Permalinks,” and click “Save Changes” to refresh your site’s permalink structure.
- Inspect
.htaccess
Configuration: Ensure that your .htaccess
file is correctly configured for a multisite network. You can find the correct rules in the Network Setup section of your WordPress dashboard.
- Verify Subdomain Configuration: Make sure that the subdomains for your multisite network are properly pointing to your WordPress installation directory.
- Check REST API Endpoint: Verify that the REST API is accessible by visiting the URL
https://[yourdomain].com/wp-json/
. If this doesn’t return a JSON response, there may be an issue with your REST API setup.
- Examine Server Logs: Look into your server logs for any error messages related to accessing a post or the REST API endpoint.
Thanks for your reply. I checked everything (except #4) and looks OK. As this was a new m/c I decided to reinstall – but I still have the same problem! So, how do you check the REST API endpoint setup? It is built into WordPress, and I have checked the config as best I can. I don’t know where to look for what has gone wrong!
Have you changed your permalink settings from the default “Plain” setting? You need to do that in order for the REST API to be accessible at https://[yourdomain].com/wp-json
.
Go to “Settings” > “Permalinks,” and try changing the value to “Post name” or “Day and name”.
Yes, I have tried each of the different Permalink options, with no effect. I’m beginning to wonder if my Apache setup is correct, although I can successfully access the website through the default and the subdomain.
This is my Apache config:
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerName my-server.com
ServerAlias *.my-server.com
SSLEngine on
# Other directives here
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/my-server.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my-server.com/privkey.pem
</VirtualHost>
</IfModule>
I’m not entirely sure what the problem could be based on the config you share but here are some ideas:
- Enable
mod_rewrite
Module: WordPress relies on the mod_rewrite
module for its permalink structure, essential for the REST API and post links to work correctly. Make sure this module is enabled in Apache. You can do this by running a2enmod rewrite
and restarting Apache.
- Update Apache Configuration: In your Apache virtual host configuration, ensure that the
AllowOverride
directive is set to All
for your document root. This allows WordPress to use .htaccess
file for URL rewriting. Add the following inside your <VirtualHost>
block:
<Directory "/var/www/html">
AllowOverride All
</Directory>
3. Check .htaccess
for Multisite Rules: Verify that your .htaccess
file contains the correct rewrite rules for a WordPress multisite installation. These rules can be slightly different from a standard WordPress install and are essential for handling URL rewrites correctly. You can find the correct .htaccess
rules in the Network Setup section of your WordPress dashboard.
Thank you so much – it was #2 (AllowOverride All) in the DocumentRoot for the WordPress directory. I’d been pouring over the https config files for hours, comparing a known working system with my new one – but I was looking at the server configs…
Anyway, lets hope that this helps other people too!
You’re welcome! Glad I could help. This idea was suggested to me by ChatGPT, by the way! 🙂
When testing the REST API, an error was encountered:
REST API Endpoint: https://*******.org/wp-json/wp/v2/types/post?context=edit
REST API Response: (http_request_failed) cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received
Any idea how to solve this error. I am using hostinger for server .
A timeout can be cause by many different things, unfortunately, including firewalls, proxies, network problems or your hosting configuration. It would probably be best to reach out to Hostinger support directly to ask for help with this.
I’m seeing this error on WP sites (self managed) when updating permalinks, or under permalinks errors list saying .htaccess is not writable.
If you *know* your permissions are solid (664/666, etc), and you are still receiving the error, confirm ownership with an ls -l at the CLI. Setting to www-data:www-data solved this issue for me.
Remember you may to restart the apache server, logout / login to backend wordpress and then give it whirl by changing the permalinks. This should resolve the API (or JSON) error message.
In case this helps someone, I too ran into the “while testing the REST API” issue. I first pursued the “AllowOverride All” solution which did not fix it. I then (lol, because I discovered all other pages besides the home page would not load) did the “Do Save on the Permalinks Settings Page” thing – which fixed my broken pages, AND, the “REST” issue. 🙂 I set “AllowOverride” back to “None” – and all still is good. I chose to do “None” as I read posts on the web of all truth that said “All” would degrade server performance.