Sometimes you need to manually clear WordPress’s rewrite rules in MySQL / PHPMyAdmin

Recently while setting up a WordPress site on a Cherokee server (no Apache/mod_rewrite), I made a little miscalculation (ahem) which resulted in the permalink structure being changed to something inaccessible, thus preventing us from being able to access the site whatsoever.

The wp-admin backend was also inaccessible because we are using a custom static login page, so access to the /wp-admin/ directory was routed to a static /login/ page (which, because of the fudged permalink rules, was unavailable. Huh?

(Long story short – servers without mod_rewrite need the start of the permalink structure to be eg. /index.php/%year%/%postname%/)

Naturally, I jumped into PHPMyAdmin to inspect the site’s options, and changed the permalink_structure in the wp_options table manually.

This won’t fix the problem if you’re unable to access the backend, though, as WordPress caches its rewrite rules until something changes in the site that would effect a permalinks flush (or until the permalinks page is visited). The cached rewrite rules will ignore the updated permalink structure, so you’re still screwed.

Solution: Manually flush WordPress’s rewrite rules with PHPMyAdmin

Find the rewrite_rules option key in the wp_options table, hit edit, and delete everything in there. Then save it. This will force WordPress to rebuild it when you try to access anything. Fixed!

This is admittedly a pretty obscure problem, but I hope it helps somebody someday.

13 thoughts on “Sometimes you need to manually clear WordPress’s rewrite rules in MySQL / PHPMyAdmin

  1. nizar

    thx for your post
    you can use update_option function like :
    update_option(‘rewrite_rules’, ”);
    and so you do not need to do it manually !

    Reply
  2. Pingback: Don’t forget to flush your … re-write rules | Andrei Lupu

  3. Marty McGee

    Ahh, nice! As you suggested, I ran this MySQL query and cleared my rewrite rules to force WordPress to rebuild the permalink structure. Thanks so much!

    SELECT * FROM wp_options WHERE option_name = 'rewrite_rules';

    Reply
  4. Terry

    This was so useful! I am trying to implement authorized protection with htaccess files in wp-admin directories. On some hosts, it was putting WP in a loop. Now my wp-admin has two logins to crack. Thanks so much for your help!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>