A strange error has occured on my Wordpress (selfhosted).

Every 4-5 page loads redirects to 404. There is no way to consistently recreate it, as a page might function or not. Its completely random. I have searched for a solution to this for hours now.

What I have tried:

  • Disable all plugins - no effect.
  • Re-install of WP, import DB, move files - no effect.
  • Change hosts (new vm) - no effect.
  • Increase compute / ram on VM - no effect.

I enabled WPDEBUG, and this is the output: http://pastebin.com/y7cQafwi

Another post on this site refers to flush_rewrite_rules as the culprit, but I have searched through all files in this WP-instance and these are the ones i found. I am not a developer so I do not know which ones are needed and not, and how I would go about removing any of them if they are not needed..

Files containing flush_rewrite:

  • ./wp-includes/class-wp-rewrite.php: if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) {
  • ./wp-includes/rewrite.php:function flush_rewrite_rules( $hard = true ) {
  • ./wp-includes/rewrite.php: * Be sure to flush the rewrite rules - see flush_rewrite_rules() - when your plugin gets
  • ./wp-includes/theme.php: flush_rewrite_rules();
  • ./wp-content/plugins/redux-framework/ReduxCore/inc/validation/unique_slug/validation_unique_slug.php: flush_rewrite_rules();
  • ./wp-content/plugins/wordpress-seo/wp-seo-main.php: add_action( 'shutdown', 'flush_rewrite_rules' );
  • ./wp-content/plugins/wordpress-seo/admin/class-admin.php: add_action( 'shutdown', 'flush_rewrite_rules' );
  • ./wp-content/plugins/wordpress-seo/inc/class-rewrite.php: update_option( 'wpseo_flush_rewrite', 1 );
  • ./wp-content/plugins/wordpress-seo/inc/class-rewrite.php: if ( get_option( 'wpseo_flush_rewrite' ) ) {
  • ./wp-content/plugins/wordpress-seo/inc/class-rewrite.php: add_action( 'shutdown', 'flush_rewrite_rules' );
  • ./wp-content/plugins/wordpress-seo/inc/class-rewrite.php: delete_option( 'wpseo_flush_rewrite' );
  • ./wp-content/plugins/wordpress-seo/inc/class-upgrade.php: add_action( 'shutdown', 'flush_rewrite_rules' ); // Just flush rewrites, always, to at least make them work after an upgrade.
  • ./wp-admin/includes/misc.php: flush_rewrite_rules();
  • ./wp-admin/includes/upgrade.php: flush_rewrite_rules();
  • ./wp-admin/includes/schema.php: flush_rewrite_rules();
  • ./wp-admin/admin.php: flush_rewrite_rules();
  • ./wp-admin/admin.php: flush_rewrite_rules(false);
  • ./wp-admin/options-permalink.php:flush_rewrite_rules();

This is my .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Any input on this issue will be greatly appriciated.

  • So this happens with a fresh standard install, with a fresh database, with permalinks turned on, the default theme, and no plugins? When you say it redirects to a 404, what do you mean? A 404 isn't a location, it's a status code, is the page giving a server 404? Or is it showing the WP 404? Is it the expected URL that has 404'd or has it redirected elsewhere? If this only happens with the plugins and themes installed, you'll need to do a process of elimination to find the simplest install that has this problem. Right now the scope is too vast/broad to know what the problem is – Tom J Nowell Mar 8 '17 at 14:51
  • As an aside, ignore the rewrite flushes in WP Core, and focus on the themes and plugins, disabling a plugin should be enough to test. Host memory etc are irrelevant ( and it would be very strange if it was ) – Tom J Nowell Mar 8 '17 at 14:55
  • Hey Tom, Thanks for getting back to me. No, not on the default theme. Standard installation works fine, its this particular theme and files that causes it I think. When i say 404 I mean that it "redirects" (pardon if the jargon is not correct) to sitename.tld/404/ and show the custom 404 from the theme. you can see it at www.itevo.no if you want to. So what happens is: If I go to either subpage, or / on the site it will sometimes reload 4-5 times and then show the 404. Or it just works like intended. Any idea why this issue is still present when I disable all plugins? – Hassan Zouhar Mar 8 '17 at 16:23
  • I am currently rebuilding the site from a vanilla install, adding plugins 1 by 1. After doing without the 404 ocurring I imported the DB from the previous site, and low and behold the 404 crops up again. same as before, random and impossible to recreate consistently. Its obvious its something in the DB. Any ideas as how I can narrow that down? EDIT: False alarm... because of items in the DB backup pointing to the original domain it fooled me. New site with plugins and DB import still working as intended. Will continue searching. – Hassan Zouhar Mar 8 '17 at 17:41
  • Hello Hassan, What was the solution for this? I have a similar problem now. – Manoj Kumar Jan 23 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.