WordPress生产环境除首页外全页面404问题排查求助
Let’s tackle this systematically—your issue boils down to a mix of missing SSL rewrite rules, permalink configuration gaps, and some environment-specific tweaks for OVH’s setup.
1. Fix the Core 404 Issue with Custom Permalinks
The missing SimpleSSL rules in .htaccess and your SSL virtual host config are almost certainly the culprit here. Let’s fix that first:
Update Your .htaccess File
Replace the existing content (if any) with this complete WordPress + SimpleSSL rule set. Make sure you’re editing the .htaccess file in your WordPress root directory:
# 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 # BEGIN Simple SSL <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] </IfModule> Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS # END Simple SSL
After saving, set the correct permissions again:
sudo chown www-data:www-data /path/to/your/wordpress/.htaccess sudo chmod 644 /path/to/your/wordpress/.htaccess
Verify Apache SSL Virtual Host Config
Open your abysolutions-le-ssl.conf file (usually in /etc/apache2/sites-available/) and make sure the <Directory> block for your WordPress root has AllowOverride All enabled. It should look like this:
<VirtualHost *:443> ServerName www.abysolutions.com ServerAlias abysolutions.com DocumentRoot /path/to/your/wordpress/root <Directory /path/to/your/wordpress/root> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> # Let's Encrypt SSL certs (auto-generated by certbot) SSLCertificateFile /etc/letsencrypt/live/abysolutions.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/abysolutions.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost>
Note: Added ServerAlias abysolutions.com to cover both www and non-www domains. Save the file, then restart Apache:
sudo systemctl restart apache2
2. Fix DNS & Site URL Mismatch
Your DNS only has an A record for abysolutions.com, but your WordPress siteurl and home are set to https://www.abysolutions.com. This can cause redirect loops and broken requests. Pick one of these fixes:
Option A: Add www DNS Record
Log into your OVH control panel and add an A record for www.abysolutions.com pointing to the same IP (146.59.234.157). Wait 10-15 minutes for DNS propagation.
Option B: Redirect Non-WWW to WWW (or Vice Versa)
If you want to stick with www.abysolutions.com as your primary domain, add this rewrite rule before the WordPress rules in .htaccess:
RewriteEngine On RewriteCond %{HTTP_HOST} ^abysolutions\.com [NC] RewriteRule ^(.*)$ https://www.abysolutions.com/$1 [L,R=301]
Or if you prefer non-www, update your WordPress siteurl and home to https://abysolutions.com and add the opposite redirect.
3. Resolve Site Health Check Errors
Fix PHP Session Interference & Loopback Timeout
The cURL error 28 (timeout) and session interference are likely because your server can’t make local requests to itself. Here’s how to fix it:
Allow Local Loopback in UFW:
Run this command to allow outgoing requests to 127.0.0.1 (your server’s local IP):sudo ufw allow in from 127.0.0.1 to any port 443Update Hosts File:
Edit your/etc/hostsfile to map your domain to the local loopback IP:sudo nano /etc/hostsAdd this line at the bottom:
127.0.0.1 www.abysolutions.com abysolutions.comSave and exit (
Ctrl+O,Enter,Ctrl+X).Check PHP Session Settings:
Ensure yourphp.inifile (location varies, e.g.,/etc/php/8.1/apache2/php.ini) has these settings:session.save_path = "/var/lib/php/sessions" session.cookie_secure = On session.cookie_httponly = OnRestart Apache after making changes:
sudo systemctl restart apache2
Fix REST API 404 & Background Updates
Once the permalink and SSL issues are fixed, the REST API should start working again. For background updates, make sure your WordPress files have the correct permissions (you already ran chown www-data:www-data and chmod 755, which is good) and that your server can reach WordPress.org’s update servers. You can verify this with:
curl -I https://api.wordpress.org/core/version-check/1.7/
If you get a 200 OK response, the connection is working.
Final Steps
- Go back to WordPress Admin → Settings → Permalinks, select your custom permalink structure, and click Save Changes (this refreshes the rewrite rules).
- Run the Site Health Check again to confirm all errors are resolved.
内容的提问来源于stack exchange,提问作者yinyang

