✨ Professional WordPress development, custom website builder, efficient on-line, cooperate and enjoy optimization services! 🚀
When WordPress moved and appeared Only the home page opens, all other pages are 404 errors The common cause of the situation is Fixed link settings are disabled (.htaccess
file has not been updated) or the pseudo-static rules are not in effectThe
You can fix this issue directly through code in several ways:
✅ I. Through code rewriting .htaccess
(Apache environment)
Add the following code to the theme's functions.php
in (only needs to be executed once, it is recommended to add a judgment to avoid multiple executions):
✅ II. Refresh fixed link structure with code (background setting equivalent operation)
You can also force a refresh of the fixed link rules in the code:
add_action('init', function () {
if (get_option('permalink_structure') ! == '/%postname%/') {
update_option('permalink_structure', '/%postname%/');
flush_rewrite_rules();
}
}).
📌 Note: You can add conditional judgment to this code, such as running it only once or executing it only when the administrator is logged in.
✅ III. In case of NGINX environments
NGINX is not supported .htaccess
You need to modify the server configuration file /etc/nginx/sites-available/your-site.conf
, adding similar rules:
✅ IV. Manual fix program (recommended to perform flush automatically after the background setup is complete)
🔁 Best Combination Suggestion:
You can combine these two paragraphs if you want to automatically fix the problems after the move:
If you are using NGINX + WordPress..htaccess
Invalid, just execute flush_rewrite_rules()
is sufficient, NGINX rules need to be configured manually or handled by Ops.