Support » Fixing WordPress » Baffling rewrite issue

  • [ Moderator note: moved to How-to and Troubleshooting. ]

    So we’re running into a very confusing rewrite issue. Our local, development and staging envs are all fine. Our production environment is the only one having the issue.

    Basically whenever we flush the rewrite rules, it will miss various rules through the system. If we flush it enough times, eventually the situation will resolve itself.

    For example, if the serialized version is a:453. We’ll flush and it will say a:314. so it’s missing a good 140 rewrites.

    We try upping memory to something ridiculous like 2048M, didn’t work.

    Think it could in any way be traffic related?

Viewing 5 replies - 1 through 5 (of 5 total)
  • My first guess is an object cache messing up your rules. Can you disable any caches (rename the object-cache.php file under wp-content if it exists) to see if that helps with this issue?

    Also, are you using wp-cli to flush the rewrite rules?

    Another thing that comes to my mind is a too clever for its own good kind of plugin doing its rewrite rules dynamically by looking at $_SERVER values or something which wouldn’t be properly populated when running in CLI mode.

    Could also be a database replication issue with your hosting where your production database wp_options table isn’t being properly replicated. I would advice you to ask your hosting company about any caching / replication type implementations they might have that could affect the production environment.

    Both good ideas, attempted both with no success. But, I think I figured it out. I think it’s a WP core scalability issue. When you flush the rewrite rules, it deletes the options. In wp_rewrite_rules there is a conditional to stop other actions from updating the rewrites in the wrong context.

    However, if I flush rewrites and while it’s processing the rewrites and another request comes in, it passes that conditional before the update_option happens, it will write it’s own rewrites.

    Here’s my gist for the solution

    Only flush_rewrites should update the rewrite rules, parse request should only get them.

    I believe the issue is that parse_request hits wp_rewrite_rules and passes if ( empty($this->rules) ) this conditional and sets the rewrites.

    My Fix,

    Don’t update the option to ”
    Pass a paramter from flush_rules to wp_rewrite_rules of true
    Set default to false in wp_rewrites rules
    Only update rewrite rules if that options is true.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Baffling rewrite issue’ is closed to new replies.